SharePoint Online: agregar acción personalizada mediante PowerShell
Requisito: Crear una acción personalizada en SharePoint Online mediante PowerShell.
¿Cómo agregar una acción personalizada en SharePoint Online?
Se recomienda la acción personalizada del usuario en SharePoint Online para personalizar la interfaz de usuario, como agregar un nuevo vínculo a la página Configuración del sitio, agregar elementos de menú, grupos de botones de cinta e inyectar JavaScript o CSS en SharePoint. A continuación se muestra un ejemplo de cómo agregar una acción personalizada en SharePoint Online:
SharePoint Online Agregar acción personalizada mediante PowerShell
Aquí está el PowerShell para crear acciones personalizadas en SharePoint Online:
#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://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 Existing Custom Actions
$Web = $Ctx.Web
$UserCustomActions= $Web.UserCustomActions
$Ctx.Load($UserCustomActions)
$Ctx.ExecuteQuery()
#Check if the CustomAction Exists already
$CustomAction = $UserCustomActions | Where { $_.Title -eq $CustomActionTitle } | Select -First 1
If($CustomAction -eq $Null)
{
#Add new custom action
$UserCustomAction = $Ctx.Web.UserCustomActions.Add()
#Set the Properties of the custom action
$UserCustomAction.Name = $CustomActionTitle
$UserCustomAction.Title = $CustomActionTitle
$UserCustomAction.Location = "Microsoft.SharePoint.SiteSettings"
$UserCustomAction.Group = "SiteTasks" #Site Actions
$UserCustomAction.Sequence = 1000
$UserCustomAction.Url = "https://Crescent-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx"
$UserCustomAction.Update()
$Ctx.ExecuteQuery()
Write-Host -f Green "Custom Action Added Successfully!"
}
Else
{
write-host -f Yellow "Custom Action Already Exists!"
}
}
Catch {
write-host -f Red "Error Adding Custom Action!" $_.Exception.Message
}
Esto agrega una acción personalizada para crear un vínculo en la configuración del sitio en SharePoint Online:
PnP PowerShell para agregar una acción personalizada en SharePoint Online
Utilice el cmdlet Add-PnPCustomAction para agregar una acción personalizada en SharePoint Online.
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive
#Add Custom Action
Add-PnPCustomAction -Name 'SharePoint Admin Center' -Title 'SharePoint Admin Center' -Description "SPO Admin Center" -Location 'Microsoft.SharePoint.SiteSettings' `
-RegistrationType List -Sequence 10000 -Group "SiteTasks" -Url "https://crescent-admin.sharepoint.com/"
