Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell - executing a script on a remote machine giving error

This following is not working for me -

%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command "& Invoke-Command -ComputerName "Spider_LT_86" -ScriptBlock { msiexec.exe /i "D:\3PDInstallers\ETLBackgroundWorkerSetup.msi" /qn /l*vx "D:\3PDInstallers\logs" }"

all I need to do is run msiexec on a remote machine. I am assuming that the user running the script will have required access to the remote machine.

The script doesn't work even when the Computername points to the local computer (and running msiexec with the same logged in user works fine, so it doesn't look like a permissions issue) - I have ensured that the WinRM service is running, and I also disabled to firewall to check whether that is the cause of issue, but no luck so far. What am I missing here?

This is the full error but it pretty much lists all possibilities -

Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using
Kerberos authentication: The network path was not found.
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 He
lp topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

UPDATE:

When I use -Credentials with just the username, it pops up a login window to get my password and then on entering it, gives the following error - the user does have admin access so I don't know what's wrong.

The

[spider_lt_86] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (:) [], PSRemotingTransportException + FullyQualifiedErrorId : PSSessionStateBroken

like image 605
Roopesh Shenoy Avatar asked Feb 06 '13 10:02

Roopesh Shenoy


People also ask

Can I run a PowerShell script on a remote computer?

Using the WS-Management protocol, Windows PowerShell remoting lets you run any Windows PowerShell command on one or more remote computers. You can establish persistent connections, start interactive sessions, and run scripts on remote computers.

What are the two ways to execute commands in PowerShell on a remote machine?

And the Invoke-Command and New-PSSession commands are two ways to execute PowerShell cmdlets on remote systems.

How do I stop a PowerShell script error?

You should be able to accomplish this by using the statement $ErrorActionPreference = "Stop" at the beginning of your scripts. The default setting of $ErrorActionPreference is Continue , which is why you are seeing your scripts keep going after errors occur. This does not affect programs, only cmdlets.


1 Answers

This is more a workaround than an answer but as you re able to use wmi why not try to create the remote process with it? Have a look here http://www.lazywinadmin.com/2011/06/powershell-launchstart-process-on.html?m=1

After comments exchange, the problem is that you had not provide a credential with administrative privilege for the remote host.

like image 90
Loïc MICHEL Avatar answered Oct 02 '22 18:10

Loïc MICHEL