Powershell正在输出字符串但未执行
Powershell输出字符串而不是执行命令Powershell正在输出字符串但未执行,powershell,cmd,command-line,Powershell,Cmd,Command Line,Powershell输出字符串而不是执行命令 $apps = @() $apps += Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit $apps += Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
$apps = @()
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
$apps365 = $apps | Where-Object {$_.DisplayName -Match "365" | Sort-Object DisplayName}
$uninPaths = @()
foreach ($item in $apps365) {
$uninPaths += "& CMD /C "+$item.UninstallString
}
Invoke-Command -ScriptBlock{$uninPaths}
$uninPaths
只是一个字符串。要像命令一样执行它,您可以将其馈送到调用表达式
:
Invoke-Expression -Command $uninPaths
Invoke命令
通常用于在远程计算机上运行powershell命令。您凭什么认为卸载字符串需要在cmd.exe
中运行?通常unistall字符串是一个标准的可执行文件,它通常接受一个或多个参数。它们不需要在特定的CLI界面中执行。为什么不直接在PowerShell CLI界面中尝试它呢?您已经在使用它了?即使使用“调用表达式”,它也只是输出字符串,而不是执行命令。