I'm try to write a code to scan a system on remote PC and also delete files from different location.
I have try following code but it didn't work.
$command = {
function::Stinger-Copy-Files
Remove-Item "C:\TEMP\*" -recurse;
Remove-Item "C:\Windows\Temp\*" -recurse;
Remove-Item "C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -recurse;
function::Stinger-Run-Scan
}
Invoke-Command -ComputerName $computerName -ScriptBlock { $command }
When I run this I get following error message
PS E:\Script\Help Script> Invoke-Command -ComputerName PC-number-ScriptBlock { $command }
[PC-number] Connecting to remote server PC-number failed with the following error message :
The client cannot connect to the destination specified in the request. Verify that the
service on the destination is running and is accepting requests. Consult the logs and
documentation for the WS-Management service running on the destination, most commonly IIS
or WinRM. If the destination is the WinRM service, run the following command on the
destination to analyze and configure the WinRM service: "winrm quickconfig". For more
information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (PC-number:String) [], PSRemotingTransportExceptio
n
+ FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
to fix this problem I have tried following code
psexec -s -e \\$computerName cmd /c winrm quickconfig -quiet
Which worked.
1. How can I make the Invoke-Command to take multiple commands
2. Enable the PSRemote commands will harm the PC. What are the down side to this.e.g. winrm quickconfig
Thank you