How to Add a Custom Action in SharePoint using PowerShell?
Requirement: Add Custom Action using PowerShell in SharePoint.
PowerShell to create a User Custom Action in SharePoint:
Here is the PowerShell to add user custom action – which adds a link to the site settings menu.
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
}
And the result of user custom action:
Here is another post to add user custom action in SharePoint Online: How to Add Custom Action using PowerShell in SharePoint Online?
Do you know what other custom action locations can be accessed with this? Possibly the screen where new users are added?
Here is the reference: https://docs.microsoft.com/en-us/sharepoint/dev/schema/default-custom-action-locations-and-ids