SharePoint 2010: Remote StsAdm using PowerShell

By | August 24, 2011


In large network, issuing a command to remote server from current terminal is sometimes necessary. Some propose client-server mode; for example Remote StsAdm ( and other propose to use PsExec (

The client-server mode requires installation of 3rd party tools. This kind of installation sometimes (or most of the time) is forbidden by company security policy.
Second option using PsExec from SysInternal (now part of Microsoft) doesn't requires installation to SharePoint server and may be the correct approach. However, I am not convince that this tools will be compatible with the future Operating System.

So, what is the option?
PowerShell and Remoting!

PowerShell has been introduced during Windows 2008 era. However, Windows 2003 server owner can apply KB968930 ( to bring PowerShell functionality to their server. PowerShell will replace because of the flexibility – enabling integration between shell and operating system itself.

Let's get our job done

1. First enable remoting on the SharePoint Server.

    Enable-PSRemoting -Force

2.  Prepare the stsadm command alias

 $executable = "$env:ProgramFiles\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" 


3.  Remember my previous post about how to avoid double hop problem? ( . Now we will create new function that uses Invoke-RemoteCommand. Basically, we will construct commandline parameter for Invoke-RemoteCommand. We also try to provide AS-IF user call stsadm.

function StsAdm 
      [string] $commandOptions,
      [string] $username,
      [string] $password
   $executable = "$env:ProgramFiles\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe"
   Invoke-RemoteCommand -commandline "'$executable' $commandOptions" -username $username -password $password

Usage : StsAdm -commandOptions "-o enumwebs" -username "setup account" -password "setup password"

And voila, you have remote stsadm function without compromising security policy.

Leave a Reply