powershell - 通过 Powershell 卸载程序
问题描述
我正在尝试通过 Powershell 卸载一些软件,并遇到了一些问题。作为一个完整的菜鸟,我正在通过反复试验将其拼凑起来。
我正在运行的脚本
##################
$appName = 'Automox'
##################
# Get all entries that match our criteria. DisplayName matches $appname, DisplayVersion less than current
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object { ($_.DisplayName -match $appName) })
# Initialize an array to store the uninstalled app information
$uninstalled = @()
# Start a loop in-case you get more than one match, uninstall each.
foreach ($version in $installed) {
#For every version found, run the uninstall string
$uninstString = $version.UninstallString
#If exe run as written + silent argument, if msiexec run as msi using the name of the reg key as the msi guid.
if ($uninstString -match 'msiexec') {
$process = Start-Process msiexec.exe -ArgumentList "/x $($version.PSChildName) /qn REBOOT=ReallySuppress" -Wait -PassThru
} else {
$process = Start-Process $uninstString -ArgumentList '/S' -Wait -PassThru
}
# Check exit code for success/fail
# Using 3 "-eq" statements becuase older PowerShell doesn't support "-in"
# If unsuccessful, don't add to uninstalled list.
if ( ($process.ExitCode -eq '0') -or ($process.ExitCode -eq '1641') -or ($process.ExitCode -eq '3010') ) {
$uninstalled += $version.PSPath
}
}
return $uninstalled
}
$uninstalledApps = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock
# Use Write-Output so you can see a result in the Activity Log
Write-Output "$uninstalledApps"
if ($uninstalledApps) {
Exit 0
} else { Exit 1 }
这是我得到的错误
At line:31 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
解决方案
推荐阅读
- laravel - 在 Laravel Jetstream / Fortify 中将登录用户重定向到个人资料页面(启用 2 因素)?
- ios - 动态集合视图单元格大小调整无法正常工作
- hadoop - 在 HIVE 中创建数据库时权限被拒绝
- excel - VBA:转换为数字
- react-native - 当视频在 expo-video-player 上以 react native 结束时如何提醒某些东西?
- go - 使用多种方式转换十六进制值会导致不同的输出
- flutter - 在 dart/flutter 中使用 [][] 从包含列表的地图索引错误
- python - 我怎样才能让 tkinter 与 time.sleep 一起工作
- python - Pythons round 函数将一半的数字四舍五入到最接近的偶数
- c - 在 C 中,如何从文本流中读取整数列表并将它们转换为数组?