I've got the start of the script to achieve this:
$SecurePassword = ConvertTo-SecureString –String $Password –AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$sess = New-PSSession -ComputerName $IPAddress -Credential $Credential
Invoke-Command -Session $sess -ScriptBlock {Get-Service}
Remove-PSSession -Session $sess
but I'm getting this connection error:
New-PSSession : [xx.xx.xx.xx] Connecting to remote server xx.xx.xx.xx failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.
- To try and get the script working I have run the
Enable-PSRemoting
command on both the client and remote servers. - As the remote server is not part of a domain, I've added the servers IP address to the
TrustedHosts
on the client server.
I've been using this page, amongst many others, to try a resolve this issue and as far as I can tell it should be working (or at least not having connection issues).
- The user I'm connecting to the remote server with is not an administrator but is part of the
Remote Managers Group
. - I've also followed the advice from this question to grant access to the service. I don't think it's getting this far but I wanted to mention it for completeness.
Any answers, advice, suggestions, etc. is greatly appreciated. Thanks.