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 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
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

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply