Solved

Running Remote Powershell script

Posted on 2012-03-21
6
4,292 Views
Last Modified: 2012-04-05
I have a script on my local machine and want to run it on a remote server:
I run this command in PowerShell ISE:

Invoke-Command -ComputerName it-xyztest -filepath C:\Scripts\XYZScript.ps1

When I run this I get the error message:
[it-xyztest] Connecting to remote server it-xyztest failed with the following error
message : Access is denied. For more information, see the about_Remote_Troubleshooting
Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken


I know nothing about the remote machine.

When I try Enter-PSSession -ComputerName it-xyztest
To test connectivity I get this:

Enter-PSSession : Connecting to remote server it-mgmt01 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. Consult the logs
and documentation for the WS-Management service running on the destination, most commonly
IIS or WinRM. If the destination is the WinRM service, run the following command on the
destination to analyze and configure the WinRM service: "winrm quickconfig". For more
information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession -ComputerName it-xyztest


This is what is in my script:
$args = '/i "\\xyz.com\gpo$\TESTInventory\TEST Inventory.msi" /quiet /norestart'
[diagnostics.process]::start("msiexec.exe", $args).WaitForExit()


All I want to do is run this .ps1 from my desktop to a remote server.

What do I have to do?  Help I'm stuck.

Thx
0
Comment
Question by:techgenious
  • 3
  • 2
6 Comments
 
LVL 39

Accepted Solution

by:
Adam Brown earned 100 total points
ID: 37748562
You have to configure the remote server to accept remote powershell commands before you can use remote powershell on it. Running winrm quickconfig on the remote server will do this for you. If you don't have RDP access to the remote server, there are a couple different ways to get this set up remotely. One is to use psexec to run the command on the remote server. Another is to deploy a GPO to the server that enables it.
0
 

Author Comment

by:techgenious
ID: 37749503
Now I was advised I do not have to run winrm quickconfig on the remote machine to run scripts to remote machines.

Then the only option your telling me is if I do not run:  winrm quickconfig on all my remote machines, I cannot run scripts remotely?

I just ran winrm quickconfig on the remote machine:

OUTPUT:
WinRM already is set up to receive requests on this machine.
WinRM already is set up to remote management on this machine.

I then ran my script:

Invoke-Command -ComputerName it-XYZtest -filepath C:\Scripts\XYZScript.ps1

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



Thx
0
 
LVL 39

Expert Comment

by:Adam Brown
ID: 37749524
In order to connect to the remote computer's Powershell session or use the invoke-command cmdlet against a remote machine, it has to be configured to accept remote management requests. winrm quickconfig does this for you. You don't have to run winrm quickconfig to do it, as there are other techniques, but it is necessary to configure the remote computer to accept requests for remoting. If you don't, remote requests are blocked by the firewall and no users are given permissions to perform remote actions against the server. You also need to configure the computer to accept remote scripts by using the set-executionpolicy cmdlet to allow remote scripts.

Also make sure that you are running the powershell session as an administrator. You may also need to enter credentials in the invoke-command cmdlet by using the -credentials switch. You can store credentials with $cred=get-credential and then passing $cred to invoke-command.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:techgenious
ID: 37750587
Thx excellent explanation.

Let me just recap since me big time beginner.   In order to run scripts remotely I need configured on remote machines.

winrm quickconfig
set-executionpolicy

Both of these can be done via GPO?
0
 
LVL 3

Assisted Solution

by:Sherif_Talaat
Sherif_Talaat earned 100 total points
ID: 37750690
First, I'd like to mention that there is an equivalent command to "winrm quickconfig" in Windows PowerShell, this cmdlet is "Set-WSMANQuickConfig" or "Enable-PSRemoting" both cmdlet are doing the same function, and it will be nice if you use "-force" with this cmdlets.

Second, There is a group policy template for Windows PowerShell allows you to configure Execution Policies using gpo. You can download it from
http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=25119

Third, WinRM group policy fall under
Computer Configuration\Policies\Administrative Templates\Windows Components\Windows Remote Management

Fourth, you can use logon scripts (VBscript or PowerShell) to execute whatever you want. So, if WinRM gpo options are not enough, you create a script that contains (winr quickconfig or Enable-PSRemoting) and assign it to your domain.
0
 

Author Closing Comment

by:techgenious
ID: 37813121
excellent response
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question