i'm new at powershell scripts
i want to uninstall softwares located in remote computer from my local computer so i'm using
$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
testing it in my local machine i got this error
Out-GridView ne fonctionne pas à partir d’une session à distance. + CategoryInfo : InvalidOperation : (Microsoft.Power...GridViewCommand:OutGridViewCommand) [Out-GridView] , NotSupportedException + FullyQualifiedErrorId : RemotingNotSupported,Microsoft.PowerShell.Commands.OutGridViewCommand + PSComputerName : 192.168.1.200
google translated:
Out-GridView does not work from a remote session. + CategoryInfo: InvalidOperation: (Microsoft.Power ... GridViewCommand: OutGridViewCommand) [Out-GridView], NotSupportedException + FullyQualifiedErrorId: RemotingNotSupported, Microsoft.PowerShell.Commands.OutGridViewCommand + PSComputerName: 192.168.1.200
but if i send a simple command like ipconfig ,it work
What i'm doing wrong ?
Out-GridViewcmdlet requires that one be in an interactive session. the session thatInvoke-Commanduses is both on the other system AND non-interactive. if you need user interaction, split your remote calls into two parts & use the returned info from the 1st in your localOut-GridViewdisplay.$JavaVervariable name ...