How to make a remote computer run PowerShell script on the remote computer itself?

4

I have two remote machines: 1 we call it the driver, 2 we call it the client. They are in the same domain let's call them "TECH.com".

On the driver machine, I have a PowerShell script that controls the client machine: 1, restore checkpoint on the client. 2, stop the client. 3, start the client. etc. The thing I am trying to do is to make the client machine execute another PowerShell script (which can reside on either/both the client or/and the driver. I can copy the file from the driver to the client if necessary) on the client machine.

So I have done some research, and found two methods: 1, WS Management. 2, WMI I have enabled-psremoting on both machines. I have test WsMan on both machines and they see to work fine I have been able to transfer files between these two machines However, when I tried to run Invoke-command, it gave me errors:

Connecting to remote server XXXXXXtech.com failed with the following error message : WinRM cannot process the request. The following 
error with errorcode 0x80090311 occurred while using Kerberos authentication: There are currently no logon servers available to service the logon request.  
 Possible causes are:
  -The user name or password specified are invalid.
  -Kerberos is used when no authentication method and no user name are specified.
  -Kerberos accepts domain user names, but not local user names.
  -The Service Principal Name (SPN) for the remote computer name and port does not exist.
  -The client and remote computers are in different domains and there is no trust between the two domains.
 After checking for the above issues, try the following:
  -Check the Event Viewer for events related to authentication.
  -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
 Note that computers in the TrustedHosts list might not be authenticated.
   -For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (XXXXXX.XXXXtech.com:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AuthenticationFailed,PSSessionStateBroken
powershell
asked on Super User Sep 17, 2013 by FrozenLand • edited Sep 17, 2013 by rtf

1 Answer

5

A couple of options:


On the local machine, allow connection to the remote machine without authentication:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value $remoteMachine -Force

If you're on the same domain and you have admin privileges on the remote machine, go ahead and try entering a remote session with your username.


Otherwise, you may need/want to set a credential object and use it to start a session for Invoke-Command.

$script = { Write-Host "Hello, World!" }
$computerName = "Server Name Or Ip Address"
$username = "domain\user"
$pw = "worstpasswordever"

# Create Credentials
$securepw = ConvertTo-SecureString $pw -asplaintext -force
$cred = new-object -typename System.Management.Automation.PSCredential -argument $username, $securepw

# Create and use session
$session = New-PSSession -credential $cred -ComputerName $computerName
Invoke-Command -Session $session -ScriptBlock $script
Remove-PSSession $session
answered on Super User Sep 17, 2013 by Anthony Neace • edited Sep 17, 2013 by Anthony Neace

User contributions licensed under CC BY-SA 3.0