我正在尝试将卸载脚本组织起来,以删除python。因为这是发生在后端,我需要它卸载静默。我做错了什么?谢谢你提前提供帮助。
$Programs = $SearchList | ?{$_.DisplayName -match ($ProgramName -join "|")}
Write-Output "Programs Found: $($Programs.DisplayName -join ", ")`n`n"
Foreach ($Program in $Programs)
{
If (Test-Path $Program.PSPath)
{
Write-Output "Registry Path: $($Program.PSPath | Convert-Path)"
Write-Output "Installed Location: $($Program.InstallLocation)"
Write-Output "Program: $($Program.DisplayName)"
Write-Output "Uninstall Command: $($Program.UninstallString)"
$UninstallString = $_.GetValue('UninstallString')
$isExeOnly = Test-Path -LiteralPath $UninstallString
if ($isExeOnly)
{
$UninstallString = "'$UninstallString'"
}
$UninstallString += '/quiet'
$Uninstall = (Start-Process cmd.exe -ArgumentList '/c', $Program.UninstallString -Wait -PassThru)
<#Runs the uninstall command located in the uninstall string of the program's uninstall registry key, this is the command that is ran when you uninstall from Control Panel.
If the uninstall string doesn't contain the correct command and parameters for silent uninstallation, then when PDQ Deploy runs it, it may hang, most likely due to a popup.#>发布于 2022-10-17 20:09:03
有几个问题:
$_而不是$_.GetValue('UninstallString')中的$Program,这很可能是导致您所看到的错误的原因。- However, `$Program.GetValue('UninstallString')` _also_ doesn't work, because (as you state it in a later comment) `$Program` is of type `[pscustomobject]`, which doesn't have a method by that name.- _If_ you obtained `$Program` via `Get-ItemProperty` (without restricting the result to specific values with `-Name`), you can access the `UninstallString` value data as follows:$Program.UninstallString
$UninstallString = "'$UninstallString'"应该是$UninstallString = "`"$UninstallString`"",因为cmd.exe只理解"..."的引用。
$UninstallString += '/quiet'应该是$UninstallString += ' /quiet',也就是说,在/quiet.之前需要一个空格
Start-Process调用中没有使用$UninstallString。https://stackoverflow.com/questions/74102315
复制相似问题