This is a continuation of part 1 and we will cover about adding a custom action in site action of the web. Note: You can think about any solution. This blog post is to show an option in PowerShell and Client Side Object Model to customize the Site Actions of the web.
- To know Default Custom Action and Location ID’s – Navigate here.
- How to work with User Custom Action – Navigate here.
Here is the sample code to add a link in Site Actions!
#Choose the Location as Microsoft.SharePoint.SiteSettings $UserCustomAction.Location = "Microsoft.SharePoint.SiteSettings" #Choose the Group as SiteTasks (Site Actions) $UserCustomAction.Group = "SiteTasks"
Site Actions Before
Site Actions After
Full Code
Import-Module C:\Temp\SharePointOnlinePowerShell\Microsoft.SharePoint.Client.dll $Admin = "Chendrayan@Contoso.onmicrosoft.com" $Password = "Password01" | ConvertTo-SecureString -AsPlainText -Force $Context = [Microsoft.SharePoint.Client.ClientContext]::new("https://contoso.sharepoint.com/Sites/PublishingPortal") $Context.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Admin,$Password) $UserCustomAction = $Context.Web.UserCustomActions.Add() #Choose the Location as Microsoft.SharePoint.SiteSettings $UserCustomAction.Location = "Microsoft.SharePoint.SiteSettings" #Choose the Group as SiteTasks (Site Actions) $UserCustomAction.Group = "SiteTasks" $UserCustomAction.Name = "Demo" $UserCustomAction.Sequence = 1000 $UserCustomAction.Url = "http://www.bing.com" $UserCustomAction.Title = "Search Bing" $UserCustomAction.Update() $Context.ExecuteQuery()
Enjoy PowerShell!