Load sharepoint envirement by powershell
#判断当前上下文环境中是否装在了SharePoint的Powershell环境,如果没有装载,则装载到当前运行环境。
$Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if($Snapin -eq $null){
Write-Output -InputObject "Loading SharePoint Powershell Snapin"
try
{
Add-PSSnapin "Microsoft.SharePoint.Powershell"
Write-Output -InputObject "Loaded SharePoint PowerShell Snapin"
}
catch
{
$(throw "There was an error loading SharePoint PowerShell Snapin")
exit
}
}