许多新的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
}

 

posted on 2012-07-07 16:00  gzh4455  阅读(317)  评论(1编辑  收藏  举报