Sky*_*969 4 powershell powershell-2.0
由于混乱的组策略对象,多个计算机不应安装TightVNC.GPO已经不见了,所以从那里删除软件并不是我所知道的选项.因此,我正在编写脚本以便从计算机列表中删除PowerShell.
这是我的脚本:
if ($args.length -ne 1) {
Write-Warning "Must pass computer name, ending script.";
break
}
$pc = $args[0]
Write-Output "Scanning $pc for TightVNC...."
$prod = wmic /node:$pc product get name | where {$_ -match "TightVNC"}
if ($prod) {
Write-Output "Found TightVNC, attempting uninstall...."
wmic /node:$pc product where name="TightVNC" call uninstall
} else {
Write-Warning "Could not find TightVNC on $pc."
}
Write-Output "Done."
Run Code Online (Sandbox Code Playgroud)
现在,我的输出如下:
Scanning [computer] for TightVNC....
Found TightVNC, attempting uninstall....
ERROR:
Description = Invalid query
Done.
Run Code Online (Sandbox Code Playgroud)
但是,如果我将第二个wmic行复制并粘贴到一个提升的命令提示符并用[computer]替换$ pc,它就可以了.我的PowerShell窗口被提升了.
有谁知道为什么我的剧本会适合这个?我知道第一个wmic命令确实需要很长时间才能完成(> = 5分钟),但它确实在第二个命令窗口中实际工作.我很欣赏对此的任何见解.
注意:我使用的是wmic,因为此处的计算机未正确配置以进行远程PowerShell访问.这是我要做的事情清单.
你正在与PowerShell的字符串解析相冲突.试试这个:
wmic /node:$pc product where name=`"TightVNC`" call uninstall
Run Code Online (Sandbox Code Playgroud)
请注意,对于PowerShell V3上的用户,您可以使用:
wmic /node:$pc --% product where name="TightVNC" call uninstall
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6159 次 |
| 最近记录: |