我试图在WPF应用程序中使用下面的Powershell脚本卸载软件。
get-package |where name -like "Notepad++ (64-bit x64)" |% { & $_.Meta.Attributes["UninstallString"] /S}上面的命令只适用于Notepad++ (64位x64),但当我尝试使用软件的Git version 2.25.1和TortoiseGit 2.10.0.0 (64位)时却失败了。
适用于Git版本2.25.1
get-package |where name -like "Git version 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S} 我得到了以下错误:
&:术语“C:\ program \Git\unins001.exe”不被识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再试一次。一行:1字符:59+."Git版本2.25.1“{& $_.Meta.Attributes"UninstallString”/S} ++ CategoryInfo : ObjectNotFound:("C:\Program \Git\unins001.exe“:String) [],CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
对于TortoiseGit 2.10.0.0 (64位)
get-package |where name -like "TortoiseGit 2.10.0.0 (64 bit)" |% { & $_.Meta.Attributes["UninstallString"] /S} 我正在犯以下错误:
管道元素中“&”之后的表达式生成一个无效的对象。它必须生成命令名、脚本块或CommandInfo对象。一行:1个字符:70+.T 2.10.0.0 (64位)“{&$_.Meta.Attributes”UninstallString}+ /S} + CategoryInfo : InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId : BadExpression
我还尝试使用WMI对象-- powershell脚本--下面是脚本
Get-WmiObject -Class Win32_Product | Where {$_.Name -like \"{returnStr}\"} | foreach {$_.Uninstall()}".Replace("{returnStr}", Notepad++ (64-bit x64)) 上面的脚本只适用于通过MSI安装的软件
如果有人有关于如何进行的建议,这将是非常感谢!
发布于 2020-03-20 10:05:09
你可以在这里找到你朋友的卸载包:
get-package | where-object name -like "Notepad++ (64-bit x64)" | ForEach {uninstall-package}发布于 2020-09-25 22:44:34
你得去掉双引号。用"代替$null或无第二arg。卸载包不适用于非msi安装。而且,这只适用于5.1,而不是当前的powershell 7。TortoiseGit有卸载字符串吗?
get-package "*Git version 2.25.1*" |
% { & ($_.Meta.Attributes["UninstallString"] -replace '"') /S} https://stackoverflow.com/questions/60771789
复制相似问题