Are you tired of having to bring up a Remote Desktop to your SharePoint server just to run an stsadm command? I sure was. Here’s a very simple way to remotely execute stsadm commands against any SharePoint server to which you have a LAN connection. Best of all, unlike some other methods out there, this method does not require deploying anything to the SharePoint server. However, this method is primarily for LAN scenarios, and it is very unlikely to work over the Internet.
What you’ll need
PsExec.exe by Sysinternals (now part of Microsoft) is a great utility that allows you to execute any command line against any Windows computer to which you have a LAN connection and proper credentials without installing any software on the remote server. PsExec sits on the workstation computer that you are using. Since stsadm is a command line tool and PsExec is designed to execute command lines, we can combine stsadm with PsExec to create a very nifty way to work on SharePoint servers remotely using only a command prompt.
PsExec uses Windows RPC ports to execute the commands, so if you will need to have the RPC ports open between your workstation and the SharePoint server that you want to manage. This is why it is unlikely to work over the Internet. This article has a nice primer on Windows TCP ports and references to other resources.
How to use PsExec with Stsadm
Here’s what you do. Remember that you will do all of these steps from your desktop computer, not the SharePoint server.
- Download PsExec from Microsoft’s web site to your computer, not to the SharePoint server.
- Open a command prompt (in administrative mode if you are using Vista with UAC enabled), and change to the directory where you have downloaded and extracted the PsExec tool.
- Execute stsadm.exe through the PsExec command. Use the following format:
psexec \[SharePoint_Server_NetBIOS_Name] –u [username] –p [password] “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINstsadm.exe” –o [stsadm_parameters]Note:
You need “\” in front of the remote SharePoint computer’s name.
Notice that all files names and paths should be absolute paths and in the context of the remote SharePoint on which you are executing the stsadm command.
A few sample commands
Here’s a sample that will enumerate all solutions:
psexec \wss01 –u mydomainadministrator –p password “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINstsadm.exe” –o enumsolutions
Here’s a sample that will do a SharePoint backup to the “c:backup folder” directory on the SharePoint server. Notice that parameters that contain spaces need to be enclosed in quotes:
psexec \wss01 –u mydomainadministrator –p password “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINstsadm.exe -o backup –directory “c:backup folder” -backupmethod full
Here’s a sample that will copy a WSP solution to a remote SharePoint server, add the solution to the solution store, and deploy the solution to the farm
REM Set an environment variable to point to stsadm. This is just for convenience
set s=“C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINstsadm.exe”
REM Copy the WSP solution file to the remote SharePoint server through the admin$ administrative share. This share points to the Windows directory. You must have administrative rights on the server to access this share. The “net use” command will establish credentials on the remote server share.
net use \wss01admin$ /USER:mydomainadministrator password
copy C:DeployMySolution.WSP \wss01admin$tempMySolution.WSP
REM Add the WSP solution to the solution store
psexec \wss01 –u mydomainadministrator –p password “%s%” –o addsolution –filename c:windowstempMySolution.WSP
REM Create a timer job to deploy the solution to all content web applications in the SharePoint farm
psexec \wss01 –u mydomainadministrator –p password “%s%” –o deploysolution -name MySolution.WSP –allcontenturls –allowgacdeployment –immediate
REM Start the deployment timer job
psexec \wss01 –u mydomainadministrator –p password “%s%” –o execadmsvcjobs
Why not PowerShell
You’ve probably noticed that I’ve been using all batch command statements in this article. The natural question to ask is: “Why not use PowerShell" instead?” After all, PowerShell is certainly far more powerful than the dated DOS commands that are available through batch files. While this is true, the fact is that PowerShell is not installed on a fairly large portion of SharePoint servers because PowerShell was not released when Windows Server 2003 came out, which still forms a very large percentage of the base operating system used for SharePoint deployments. Because one of the goals of this article was to come up with a remote SharePoint management method that could be used with all LAN SharePoint servers with no additional server software install, PowerShell was out.
Another option — enable telnet on the server.
Thanks, Michael. That is a valid option, but like several other options it requires a configuration change to each SharePoint server against which you want to run remote commands, since Telnet is not installed by default with Windows server or SharePoint.
Hi,
Thanks for sharing this great tip. I am still having a problem getting it to work. every time I execute a simple stsadm operation, it fails with the following error:-
The command:-
psexec e1knoxd0041 -u espdevsrv-moss -p bl0gg! "C:Program FilesCommon Filesmicrosoft sharedweb server extensions12binstsadm.exe" -o enumsites -url http://e1knoxd0041:10004
The Error:-
"Sites Count="1"
Site Error="Unable to connect to database. Check database connection information and make sure the database server is running."
Sites C:Program FilesCommon Filesmicrosoft sharedweb server extensions12binstsadm.exe exited on e1knoxd0039 with error code 0."
I have made sure that sql server is set up to accept remote connection, I am not sure if I missed on anything.
Wael, it seems that the psexec command is returning exit code 0, which indicates that it succeeded in running the stsadm command remotely. I would then guess that you are truly getting an stsadm error. I would try logging in to the console of the SharePoint machine with the espdevsrv-moss / bl0gg! credentials and run the stsadm command locally.
http://code.msdn.microsoft.com/office/Remote-StsAdm-in-6fec24b8
Cool resource. Thanks.