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.

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *