当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 在 SharePoint 中添加自定义操作?

作者:精品下载站 日期:2024-12-14 14:39:14 浏览:15 分类:玩电脑

如何使用 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
}

以及用户自定义操作的结果:

[玩转系统] 如何使用 PowerShell 在 SharePoint 中添加自定义操作?

这是在 SharePoint Online 中添加用户自定义操作的另一篇文章:如何在 SharePoint Online 中使用 PowerShell 添加自定义操作?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯