SharePoint Online: Remove Custom Action Using PowerShell CSOM
Requirement: Delete a Custom Action in SharePoint Online using PowerShell
SharePoint Online: PowerShell to Remove Custom Action
Here is the PowerShell CSOM script to remove custom action.
SharePoint Online: PowerShell to Remove Custom Action
Here is the PowerShell CSOM script to remove custom action.
#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #Set parameter values $SiteURL="https://crescenttech.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 }This deletes all custom actions with the provided title. You can get and delete them using its name, id or other parameters as well.
No comments:
Please Login and comment to get your questions answered!