如何使用 PowerShell 在 SharePoint 中添加自定义操作?
要求:在 SharePoint 中使用 PowerShell 添加自定义操作。
PowerShell 在 SharePoint 中创建用户自定义操作:
下面是用于添加用户自定义操作的 PowerShell,它添加了指向站点设置菜单的链接。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Set Site variable
$SiteURL="https://intranet.crescent.com"
$CustomActionTitle ="Support Center"
Try {
#Get the Web
$Web = Get-SPWeb $SiteURL
#Check if the Custom Action Exists already
$CustomAction = $web.UserCustomActions | Where { $_.Title -eq $CustomActionTitle }
If($CustomAction -eq $Null)
{
#Add new custom action
$UserCustomAction = $web.UserCustomActions.Add()
#Set the Properties of the custom action
$UserCustomAction.Title = $CustomActionTitle
$UserCustomAction.Location = "Microsoft.SharePoint.StandardMenu"
$UserCustomAction.Group = "SiteActions" #Site Settings Menu
$UserCustomAction.Sequence = 1000
$UserCustomAction.Url = "https://intranet.crescent.com/support/"
$UserCustomAction.Description = "Crescent Inc. Support Center"
$UserCustomAction.Update()
Write-Host -f Green "Custom Action Added Successfully!"
}
Else
{
write-host -f Yellow "Custom Action Already Exists!"
}
} Catch {
Write-Host -ForegroundColor Red "Error:" $_.Exception.Message
}
以及用户自定义操作的结果:
这是在 SharePoint Online 中添加用户自定义操作的另一篇文章:如何在 SharePoint Online 中使用 PowerShell 添加自定义操作?
