英文:
How do I do a windows registry wait loop in PowerShell
问题
Intune给我带来了麻烦,我尝试使用Powershell安装一个程序,通常只需要在最后加上 -wait
,脚本就会等待安装完成然后关闭,但是在Intune中它会挂起。
所以我想要做的是创建一个等待循环,以便在创建这个Windows注册表时:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{AA3C5F33-570B-3989-8542-D5DC0F759221}
并且这个名称字段等于这个数字:
DisplayVersion = 21.1.21.45
以下是PowerShell脚本的尝试:
$regkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}'
$DisplayVersion = '21.1.21.45'
$Notdone = $true
DO {
$exists = Get-ItemProperty -Path $regkey -Name $DisplayVersion -ErrorAction SilentlyContinue
if (($exists -ne $null) -and ($exists.Length -ne 0)) {
& "C:\Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\installer.exe" -ArgumentList "-i deploy --offline_mode -o C:/Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\Collection.xml --installer_version 1.35.0.9"
$Notdone = $false
}
else {
Start-Sleep -Seconds 15
}
} While ($Notdone)
希望这能帮助你解决问题。
英文:
Intune is giving me the S**t's I am trying to install a program with Powershell and usually, you just put -wait at the end and the scrips wait's until the install is done and then closes but with intune it just hangs.
so what I want to do is put in a wait loop so that when this windows registry is created
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{AA3C5F33-570B-3989-8542-D5DC0F759221}
With this name field equaling this number
DisplayVersion = 21.1.21.45
Below is attempt at the PowerShell script
$regkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}'
$DisplayVersion = '21.1.21.45'
$Notdone = $true
DO {
$exists = Get-ItemProperty -Path $regkey -Name $DisplayVersion -ErrorAction SilentlyContinue
if (($exists -ne $null) -and ($exists.Lenght -ne 0)) {
& "C:\Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\installer.exe" -ArgumentList "-i deploy --offline_mode -o C:/Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\Collection.xml --installer_version 1.35.0.9"
$Notdone = $false
}
else {
Start-Sleep -Seconds 15
}
} While ($Notdone)
答案1
得分: 1
你每隔15秒重新启动安装
$regkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}'
$DisplayVersion = '21.1.21.45'
$Notdone = $true
Start-Process "C:\Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\installer.exe" -ArgumentList "-i deploy --offline_mode -o C:/Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\Collection.xml --installer_version 1.35.0.9" -Wait -NoNewWindow
DO {
$exists = Get-ItemProperty -Path $regkey -Name $DisplayVersion -ErrorAction SilentlyContinue
if ([string]::IsNullOrEmpty($exists)){
$Notdone = $true
Start-Sleep -Seconds 15
}else {$Notdone = $false}
} While ($Notdone)
英文:
you restart the installation every 15 seconds
$regkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}'
$DisplayVersion = '21.1.21.45'
$Notdone = $true
Start-Process "C:\Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\installer.exe" -ArgumentList "-i deploy --offline_mode -o C:/Autodesk\{D138465E-4098-4F01-B453-1C4BEADE75D8}\image\Collection.xml --installer_version 1.35.0.9" -Wait -NoNewWindow
DO {
$exists = Get-ItemProperty -Path $regkey -Name $DisplayVersion -ErrorAction SilentlyContinue
if ([string]::IsNullOrEmpty($exists)){
$Notdone = $true
Start-Sleep -Seconds 15
}else {$Notdone = $false}
} While ($Notdone)
答案2
得分: 0
以下是对您提供的代码的翻译部分:
这是对我有效的代码
[Version]$minVersion = "21.1.21.45";
do {
$version = [Version]'0.0.0.0'; try { [Version]$version = [Version](Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}' -EA 0).DisplayVersion; } catch { }
if ($version -ge $minVersion) {
#Write-Host "The version is now '$($version)', which is greater than the Minimum version '$($minVersion)'";
}
else {
#Write-Host "The version is now '$($version)', which is less than the Minimum version '$($minVersion)'. Will wait 15secs.";
Start-Sleep -Seconds 15;
}
}
until($version -ge $minVersion);
请注意,这只是代码的翻译部分,不包括注释和注释内的文本。
英文:
here is the code that worked for me
[Version]$minVersion = "21.1.21.45";
do {
  $version = [Version]'0.0.0.0'; try { [Version]$version = [Version](Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AA3C5F33-570B-3989-8542-D5DC0F759221}' -EA 0).DisplayVersion; } catch { }
  if ($version -ge $minVersion) {
  #Write-Host "The version is now '$($version)', which is greater than the Minimum version '$($minVersion)'";
  }
  else {
  #Write-Host "The version is now '$($version)', which is less than the Minimum version '$($minVersion)'. Will wait 15secs.";
  Start-Sleep -Seconds 15;
  }
}
until($version -ge $minVersion);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论