加载 SharePoint 管理单元

可以使用以下方法加载 SharePoint Snapin:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

**这仅适用于 64 位版本的 PowerShell。**如果窗口在标题中显示“Windows PowerShell(x86)”,则说明你使用的版本不正确。

如果已加载管理单元,则上面的代码将导致错误。使用以下内容仅在必要时加载,可以在 Cmdlet /函数中使用:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

或者,如果启动 SharePoint Management Shell,它将自动包含 Snap-In。

若要获取所有可用 SharePoint Cmdlet 的列表,请运行以下命令:

Get-Command -Module Microsoft.SharePoint.PowerShell