SharePoint Automation Parte 1 

Tags: Administração, SharePoint2010, SharePoint

 
SharePoint Automation -   Parte 1
 
Carissímos,
gostaria de partilhar com vocês um powershell script que costumo utilizar em nos diferentes ambientes que me passam pelas mãos.
 
Tem como objectivo , adicionar à variável de ambiente PATH, o caminho completo onde normalmente o executável stsadm está instalado.
 
Todos nós sabemos que é moroso e pouco prático, a digitação de "C:\Program Files\Common File\etc etc etc" cada vez que quisermos utilizar o SharePoint Team Services Administration (sabiam que se chamava assim?)
 
Tendo rescrito o script à pouco tempo , resolvi fazer este post e partilhar com vocês, este mimo.
 
 
""
"####################################################################"
"#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
 
 
Se tudo correr bem se abrirem um novo command-prompt e digitarem stsadm, verificam que já foi adicionado.
 
By the way, PowerShell really rocks! Se ainda não sabem o que é ou tweakaram com ele ... bem ... estão a perder muita coisa, mesmo.
 
 
Abraços e muitos Disposes à mistura...
 
 
 
 
Rodrigo Pinto
SharePoint Specialist,Evangelist
SharePointPt Founder
Company:INDRA
@scoutmanpt

 
 
Posted em 13-Jan-11
1 Comentários  |  Trackback Url  |  Link para este post | Bookmark este post com:        
 

Links para este post

Comentários


Bruno Sousa comentou em Monday, 17-Jan-2011
Viva, ja agora uma outra dica... Caso nao pretendam alterar a variavel PATH, podem definir uma variavel local na consola PS: $stsadm = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\STSADM.EXE" e executar o STSADM.exe, exemplo: & $stsadm -help restore

Nome:
URL:
Email:
Comentário: