许多新的PowerShell 程序员可能会陷入没有引用SharePoint PowerShell snap-in 的困境。以下代码列举了如何避免陷入这样的困境。
$snapin = Get-PSSnapin | where-object { $_.Name -eq 'Microsoft.SharePoint.PowerShell' } if ($snapin -eq $null){ write-host "Loading SharePoint PowerShell Snapin..." -foregroundcolor Blue add-pssnapin "Microsoft.SharePoint.PowerShell" write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
}