I have written powershell script which connects to a remote server and executes a batch file
$password = ConvertTo-SecureString "pwd" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("user", $password )
Invoke-Command -ComputerName 10.10.10.10 -credential $cred -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /c 'C:\batchfile.bat'"}
but i am getting an error:
[10.10.10.10]Error while connecting to the server: The WinRM client
cannot process the request. Default authentication may be used with an
IP address under the following conditions: the transport is HTTPS or
the destination is in the TrustedHosts list, and explicit
credentials are provided. Use winrm.cmd to configure TrustedHosts.
Note that computers in the TrustedHosts list might not be
authenticated. For more information on how to set TrustedHosts run
the following command: winrm help config. For more information, see
the about_Remote_Troubleshooting Help topic At line:1 char:1
+ Invoke-Command -ComputerName 10.10.10.10 -credential $cred -ErrorAct ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (10.10.10.10:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : CannotUseIPAddress,PSSessionStateBroken
I got stuck. Please help me in this issue.
I have tried adding the name to the Trusted host also