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
3) Create a PowerShell script to execute your desired command remotely using the Invoke-Command cmdlet
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
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