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 the STSADM.EXE file’s location to the “Path” environment variable in SharePoint servers in order to access stsadm anywhere from command lines and batch files. Failed to do so will result in an 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.
How to add stsadm to the “Path” variable in SharePoint 2013?
To access stsadm anywhere, we’ll have to add stsadm command-line tool’s location to the “Path” environment variable in the 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
PowerShell script to add STSADM to Path variable in SharePoint
Now, the PowerShell way! How to add STSADM to the 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
if($PathVariable.Trim().EndsWith(";"))
{
$PathVariable = $PathVariable + $STSADMPath
}
else
{
$PathVariable = $PathVariable +";"+ $STSADMPath
}
#Add STSADM Folder to path to variable
[System.Environment]::SetEnvironmentVariable("Path", $PathVariable, "Machine")
write-host "Path environment variable updated with STSADM..."
}
Similarly, for SharePoint 2016, use the path C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\BIN
Related post: Set STSADM path in SharePoint 2007, SharePoint 2010