I need to clear a folder on a remote server before copying new files to it.
So the script on my client contains the following:
Invoke-Command -Computer $TargetServer -ScriptBlock { Remove-Item $ClearPath }
When I run this I get the following error:
Connecting to remote server 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
I looked this up on technet, my understanding from this was that if the servers use a proxy (which mine do when trying to get to the internet) then I need to use the $PSSessionOption object. So I changed my script so that the following is first executed:
$User = "group\tfs_service"
$Password = ConvertTo-SecureString -String "x" -AsPlainText -Force
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Password
$PSSessionOption = New-PSSessionOption -ProxyAccessType IEConfig -ProxyAuthentication Negotiate -ProxyCredential $Credential
Now when I run the script I get the following error:
Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Setting proxy information is not valid when the HTTP transport is specified. Remove the proxy information or change the transport and try the request again
Can anyone please tell me where I’m going wrong?
It seems I was barking up the wrong tree thinking I needed to configure the proxy. The only problem was that I hadn’t enabled powershell remoting on the remote server. I was able to do this by executing the following command in an elevated powershell window: