Jason Yu
asked on
why the script shows "Couldn't connect to remote machine"
I have a script to remove a specific patch I installed several days ago from a list of computers. The code is as below:
When I ran this script, it uninstalled the hotfix but in the progress of running it, it gave me error message like below, could you please help me with this:
PS C:\PowerShell Scripts> .\patch_remove.ps1
Given hotfix(KB3097877) not found
Given hotfix(KB3097877) not found
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1 8 char:14
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc eption,Mic rosoft.Pow erShell.Co mmands.Get ProcessCom mand
Completed the uninstallation of 3097877
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1 8 char:14
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc eption,Mic rosoft.Pow erShell.Co mmands.Get ProcessCom mand
Completed the uninstallation of 3097877
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1 8 char:14
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc eption,Mic rosoft.Pow erShell.Co mmands.Get ProcessCom mand
function Uninstall-Hotfix {
[cmdletbinding()]
param(
$computername = $env:computername,
[string] $HotfixID
)
$hotfixes = Get-WmiObject -ComputerName $computername -Class Win32_QuickFixEngineering | select hotfixid
if($hotfixes -match $hotfixID) {
$hotfixID = $HotfixID.Replace("KB","")
Write-host "Found the hotfix KB" + $HotfixID
Write-Host "Uninstalling the hotfix"
$UninstallString = "cmd.exe /c wusa.exe /uninstall /KB:$hotfixID /quiet /norestart"
([WMICLASS]"\\$computername\ROOT\CIMV2:win32_process").Create($UninstallString) | out-null
while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyContinue).Count -ne 0) {
Start-Sleep 3
Write-Host "Waiting for update removal to finish ..."
}
write-host "Completed the uninstallation of $hotfixID"
}
else {
write-host "Given hotfix($hotfixID) not found"
return
}
}
$myComputers = Get-Content "c:\PowerShell Scripts\computers_needremove.txt"
foreach ($computer in $myComputers) {
Uninstall-HotFix -ComputerName $computer -HotfixID KB3097877
}
When I ran this script, it uninstalled the hotfix but in the progress of running it, it gave me error message like below, could you please help me with this:
PS C:\PowerShell Scripts> .\patch_remove.ps1
Given hotfix(KB3097877) not found
Given hotfix(KB3097877) not found
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc
Completed the uninstallation of 3097877
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc
Completed the uninstallation of 3097877
Found the hotfix KB + 3097877
Uninstalling the hotfix
Get-Process : Couldn't connect to remote machine.
At C:\PowerShell Scripts\patch_remove.ps1:1
+ while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Process], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationExc
winrm may not be enabled or running on the destination computer.
ASKER
Then How to resolve this?
What is winrm? Could I install them remotely?
thanks.
What is winrm? Could I install them remotely?
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
good answers, thank you all.