Monday, April 14, 2014

Add stsadm to Path Environment Variable in SharePoint Servers

STSADM is still alive in SharePoint 2013 and in some cases we need to run this command line tool! We've to add STSADM.EXE file's location to "Path" environment variable in SharePoint servers, in order to access stsadm anywhere from command lines and from batch files. Failed to do so will result in error "'stsadm' is not recognized as an internal or external command, operable program or batch file." or we'll have to specify its full path every time we run this tool.

stsadm' is not recognized as an internal or external command
How to add stsadm to "Path" variable in SharePoint 2013
To access stsadm anywhere, we'll have to add stsadm command line tool's location to "Path" environment variable in Windows server. Navigate to:
  • Control Panel >> System and Security >> System >> Advanced System Settings (Shortcut: sysdm.cpl)
  • Advanced >> Environment Variables >> Under "System" variables Click on "Path" and "Edit"
  • Append the path of STSADM.exe folder location with this "path" variable. stsadm default path: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\BIN
Add stsadm to Path Environment Variable

PowerShell script to add STSADM to Path variable in SharePoint
Now, the PowerShell way! How to add STSADM to path variable using PowerShell?
#STSADM Folder location in SharePoint 2013
$STSADMPath = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\BIN"

#Get the current environment variable
$PathVariable = [Environment]::GetEnvironmentVariable("Path","Machine")

#Get each folder in Path variable:
$PathFolders = $PathVariable.Split(";")

#Check if the STSADM folder already exists in "PATH" Variable
if ($PathFolders.Contains($STSADMPath))
 Write-Host "STSADM Folder already exists in PATH variable!"
else #Add to PATH variable
    #Frame Path variable by appending STSADM 
        $PathVariable = $PathVariable + $STSADMPath
        $PathVariable = $PathVariable +";"+ $STSADMPath

    #Add STSADM Folder to path to variable
 [System.Environment]::SetEnvironmentVariable("Path", $PathVariable, "Machine")

    write-host "Path environment variable updated with STSADM..."

Related post: Set STSADM path in SharePoint 2007, SharePoint 2010

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...