I'm trying to run a batch script on a remote server via powershell. Pretty straight forward:
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("domain\user", $password)
$sesh= new-pssession -computername "MSSCA" -credential $cred
invoke-command -session $sesh -scriptblock {
cmd.exe /C "C:\install.bat"
}
Remove-PSSession $sesh
This seems to randomly fail with the following error
On the remote machine, running the powershell command winrm quickconfig
to configure the remote management service informs me that it's already set up to receive requests/remote management.
Only AFTER running this command will invoke-command
go through properly. How? I didn't even configure anything. How can I fix this?