【发布时间】:2019-10-10 00:35:43
【问题描述】:
我是 powershell 脚本的新手
我想从本地计算机上卸载位于远程计算机上的软件 所以我正在使用
$computer =Read-Host -Prompt 'Input your server name or IP adress'
$user =Read-Host -Prompt 'Input your server username'
Invoke-Command -ComputerName $computer -ScriptBlock {
Write-host -ForegroundColor Magenta "Please select the software you wish to uninstall..."
$javaVer = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select DisplayName, UninstallString, InstallLocation, InstallDate | out-gridview -PassThru
write-host -ForegroundColor Yellow "The following software will be uninstalled:"
ForEach ($ver in $javaVer) {
If ($ver.UninstallString) {
$uninst = $ver.UninstallString
& cmd /c $uninst /quiet /norestart
}
}
} -credential $user
在我的本地机器上测试我得到了这个错误
Out-GridView ne fonctionne pas à partir d'une sessionà 距离。 + CategoryInfo : InvalidOperation : (Microsoft.Power...GridViewCommand:OutGridViewCommand) [Out-GridView] , NotSupportedException + FullyQualifiedErrorId:RemotingNotSupported,Microsoft.PowerShell.Commands.OutGridViewCommand + PSComputerName : 192.168.1.200
谷歌翻译:
Out-GridView 在远程会话中不起作用。 + 类别信息: 无效操作:(Microsoft.Power ... GridViewCommand: OutGridViewCommand) [Out-GridView], NotSupportedException + FullyQualifiedErrorId:RemotingNotSupported, Microsoft.PowerShell.Commands.OutGridViewCommand + PSComputerName: 192.168.1.200
但是如果我发送一个像ipconfig 这样的简单命令,它就可以工作
我做错了什么?
【问题讨论】:
-
Out-GridViewcmdlet 要求处于交互式会话中。Invoke-Command使用的会话既在另一个系统上又是非交互式的。如果您需要用户交互,请将您的远程调用分成两部分并在本地Out-GridView显示中使用第一部分返回的信息。 -
@Lee_Dailey 对不起,我还在学习 powershell 脚本,你能修改代码并将其作为答案发布吗?
-
您是否只想卸载特定的应用程序 - 也许是 java?您的
$JavaVer变量名暗示了这一点... -
@Lee_Dailey 不,我想从打开的列表中选择要卸载的软件或输入软件名称,但从列表中选择对我来说更容易
-
OK ...我认为我刚刚发布的 ANSWER 中的代码可以工作,但我无法完全测试,因为我只有一个系统 - 并且没有要卸载的应用程序。 [咧嘴]
标签: powershell