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

[玩转系统] SharePoint Online:使用 PowerShell CSOM 删除自定义操作

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

SharePoint Online:使用 PowerShell CSOM 删除自定义操作


要求:使用 PowerShell 删除 SharePoint Online 中的自定义操作。

SharePoint Online:用于删除自定义操作的 PowerShell

以下是用于删除自定义操作的 PowerShell CSOM 脚本:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$CustomActionTitle = "SharePoint Admin Center"
 
Try{
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get All Custom Actions
    $Web = $Ctx.Web
    $UserCustomActions= $Web.UserCustomActions
    $Ctx.Load($UserCustomActions)
    $Ctx.ExecuteQuery()

    #Get Custom Action(s) to delete
    $CustomActions = $UserCustomActions | Where { $_.Title -eq $CustomActionTitle }

    If($CustomActions -ne $Null)
    {
        #Delete all custom actions
        $CustomActions | ForEach-Object {
            #Remove the custom action
            $_.DeleteObject()
            Write-Host -f Green "Custom Action '$($_.Name)' Deleted Successfully!"
        }
        $Ctx.ExecuteQuery()
    }
    Else
    {
         write-host -f Yellow "Custom Action Does not Exist!"
    }
}
Catch {
        write-host -f Red "Error Removing Custom Action!" $_.Exception.Message
}

这将删除具有所提供标题的所有自定义操作。您还可以使用它们的名称、ID 或其他参数来获取和删除它们。

用于删除 SharePoint Online 中的自定义操作的 PnP PowerShell

使用Remove-PnPCustomAction PnP cmdlet 删除SharePoint Online 中的自定义操作。


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"

#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get Custom Actions
Get-PnPCustomAction

#Remove Custom Action
Remove-PnPCustomAction -Identity "SharePoint Admin Center" -Force

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

取消回复欢迎 发表评论:

关灯