Powershell删除已安装的应用程序
是否可以通过发布者名称删除软件。我尝试过不同的方法来做到这一点,但我没能做到。我可以使用名称来删除它,但有些程序名称不匹配,但发布者是相同的。
例如
Get-WmiObject -Class Win32_Product -ComputerName $PCNumber -Filter "Publisher LIKE '%$Publisher%'" | Foreach-Object {
Write-Host
Write-Host "Uninstalling: $($_.Name)"
Write-Host
$rv = $_.Uninstall().ReturnValue
if($rv -eq 0)
{
$remove = "$drive\Program Files\software\";
if ( (Test-Path "$remove") ){
Remove-Item $remove -Recurse -Force
}
$remove = "$drive\Program Files (x86)\software\";
if ( (Test-Path "$remove") ){
Remove-Item $remove -Recurse -Force
}
Write-Host "$($_.Name) uninstalled sucessfully"
}
else
{
Write-Host "There was an error ($rv) uninstalling $($_.Name)"
}
}
我已经尝试过但失败了。
Is it possible to remove software by the publisher name. I have tried different ways to do it but I was not able to. I can use name to remove it but some programs name doesn't match but the publisher is same.
e.g.
Get-WmiObject -Class Win32_Product -ComputerName $PCNumber -Filter "Publisher LIKE '%$Publisher%'" | Foreach-Object {
Write-Host
Write-Host "Uninstalling: $($_.Name)"
Write-Host
$rv = $_.Uninstall().ReturnValue
if($rv -eq 0)
{
$remove = "$drive\Program Files\software\";
if ( (Test-Path "$remove") ){
Remove-Item $remove -Recurse -Force
}
$remove = "$drive\Program Files (x86)\software\";
if ( (Test-Path "$remove") ){
Remove-Item $remove -Recurse -Force
}
Write-Host "$($_.Name) uninstalled sucessfully"
}
else
{
Write-Host "There was an error ($rv) uninstalling $($_.Name)"
}
}
I have tried this but it failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)