""
"####################################################################"
"#Script to add to the PATH Environment variable , stsadm fullpath"
"####################################################################"
""
""
$Hive ="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\{0}\bin\"
$SPS2007= "12"
$SPS2010= "14"
#Getting Path Variable
$env =[Environment]::GetEnvironmentVariable("PATH","Machine")
#Settng $add variable to null
$add = ""
#Testing Path for SharePoint Sharepoint 2007 and SharePoint 2010.
if (Test-Path([string]::Format( $Hive, $SPS2007)) ) {$add = [string]::Format( $Hive, $SPS2007) }
if (Test-Path ([string]::Format( $Hive, $SPS2010)) ) {$add = [string]::Format( $Hive, $SPS2010) }
#If $add is not set then no sharepoint exists
if ($add -eq "")
{
"MSG: Yup, there is no SharePoint in the system! Now what? "
""
return
}
#If $add is not set then no sharepoint env. exists
if ($env.Contains($add))
{
[string]::Format("MSG:PATH already have '{0}' inside.", $add)
"Glad i caught the mistake! "
return
}
#if all went well set the stsamd path to the environment variable
[string]::Format("MSG:Adding to the PATH Environment this path:'{0}'", $add)
$env = $env + ";" + $add
[Environment]::SetEnvironmentVariable("Path",$env,"Machine")
#This next lines are not necessary , they only exists to verify if the PATH was changed
$env =[Environment]::GetEnvironmentVariable("PATH","Machine")
""
"MSG:Path Variable content bellow"
""
$env