Solved

Running Remote Powershell script

Posted on 2012-03-21
6
4,437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

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 40

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy-Item -UseTransaction not working 2 37
Open new WPF windows - powershell 4 37
Access PS SQLSERVER from powershell 1 29
Get-PSDrive results 2 20
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

734 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