Skip to main content


Using PowerShell 2.0 to Execute STSADM Commands Remotely

In version 2.0, PowerShell includes the capability to execute commands on remote computers via the WinRM service. WinRM is Microsoft’s implementation of the WS-Management protocol. We recently took advantage of this capability to automate SharePoint solution upgrades to our integration environment from our build server.

This can be accomplished in four easy steps:

1) Upgrade both the client machine (build server) and the server machine (a web front-end in the integration farm) to use PowerShell 2.0 by installing the Windows Management Framework RC.

2) Run the Enable-PSRemoting cmdlet on both machines to setup WinRM

Example 1

3) Create a PowerShell script to execute your desired command remotely using the Invoke-Command cmdlet

Example 2

The script above will allow you to specify the remote server name at run-time and assumes that the identity executing the script has administrator rights on both the client and server machines.

4) Update your MSBuild targets to include a step to copy WSPs to the integration environment and execute your PowerShell script

Example 3

This target does the following:

  • Copy WSP files to the drop location
  • Copy CAB files to the drop location
  • Copy WSP files to a file share on the integration server
  • Set the PowerShell script execution policy to "RemoteSigned" to allow script execution on the client machine
  • Execute the script to run STSADM on the server machine

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us