SharePoint Online: ค้นหาการดำเนินการแบบกำหนดเองทั้งหมดโดยใช้ PowerShell
ข้อกำหนด: ค้นหาการดำเนินการแบบกำหนดเองทั้งหมดใน SharePoint Online
PowerShell เพื่อรับการดำเนินการแบบกำหนดเองของผู้ใช้ทั้งหมดใน SharePoint Online:
การกระทำแบบกำหนดเองเป็นกลไกที่มีประสิทธิภาพในการเพิ่มการปรับแต่งบน SharePoint ฉันมีข้อกำหนดในการเตรียมรายการการกระทำแบบกำหนดเองทั้งหมดบนไซต์ใดไซต์หนึ่ง และนี่คือสคริปต์ PowerShell เพื่อค้นหาการดำเนินการแบบกำหนดเองบนไซต์ที่กำหนด
#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/"
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
$UserCustomActions= $Ctx.Web.UserCustomActions
$Ctx.Load($UserCustomActions)
$Ctx.ExecuteQuery()
If($UserCustomActions.count -gt 0)
{
ForEach($CustomActions in $UserCustomActions)
{
Write-Host -f Green "Custom Action Name: '$($CustomActions.Name)' ID: $($CustomActions.ID)"
}
}
Else
{
write-host -f Yellow "No Custom Actions Found!"
}
}
Catch {
write-host -f Red "Error Getting Custom Actions!" $_.Exception.Message
}
สคริปต์นี้แสดงรายการการกระทำที่กำหนดเองของผู้ใช้ทั้งหมดของเว็บที่กำหนด คุณสามารถเปลี่ยนวัตถุเป็นไซต์เพื่อค้นหาการกระทำแบบกำหนดเองทั้งหมดของวัตถุไซต์ได้ เช่น $UserCustomActions= $Ctx.เว็บ.UserCustomActions ถึง $UserCustomActions= $Ctx.ไซต์.UserCustomActions
PowerShell เพื่อค้นหาการดำเนินการแบบกำหนดเองทั้งหมดในคอลเลกชันไซต์ SharePoint Online:
มาเปลี่ยนสคริปต์ด้านบนเล็กน้อยเพื่อวนซ้ำไซต์ย่อยทั้งหมดจากไซต์คอลเลกชันที่กำหนดเพื่อรับรายการการกระทำที่กำหนดเองของผู้ใช้ทั้งหมดสำหรับทั้งไซต์และออบเจ็กต์เว็บ และส่งออกสิ่งที่เราค้นพบเป็นไฟล์ CSV
#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"
Function Get-SPOCustomActions([String]$SiteURL,[String]$Scope)
{
Try{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Web and Sub Sites
$Ctx.Load($Ctx.Web)
$Ctx.Load($Ctx.Web.Webs)
$Ctx.ExecuteQuery()
#Get All Custom Actions based on given scope: Site or Web
If($Scope -eq "Site")
{
$UserCustomActions= $Ctx.Site.UserCustomActions
Write-host -f Yellow "Searching $Scope Scoped Custom Actions at '$SiteURL'"
}
ElseIf($Scope -eq "Web")
{
$UserCustomActions= $Ctx.Web.UserCustomActions
Write-host -f Yellow "Searching $Scope Scoped Custom Actions at '$SiteURL"
}
$Ctx.Load($UserCustomActions)
$Ctx.ExecuteQuery()
$CustomActionsData = @()
ForEach($CustomAction in $UserCustomActions)
{
Write-Host -f Green "Found a Custom Action: '$($CustomAction.Name)' at : $($SiteURL)"
#Get Custom Action Data
$CustomActionsData += New-Object PSObject -Property @{
'Site URL' = $SiteUrl
'Custom Action Title' = $CustomAction.Title
'Name' = $CustomAction.Name
'ID' = $CustomAction.ID
'Group' = $CustomAction.Group
'Location' = $CustomAction.Location
'Sequence' = $CustomAction.Sequence
'Url' = $CustomAction.Url
'Scope' = $CustomAction.Scope
'ScriptBlock' = $CustomAction.ScriptBlock
'ScriptSrc' = $CustomAction.ScriptSrc
}
}
#Export the data to CSV
$CustomActionsData | Export-Csv $ReportOutput -NoTypeInformation -Append
#Get the Root Web's Custom Actions
If($Scope -eq "Site")
{
#Call the function to get Root Web's Custom Actions
Get-SPOCustomActions -SiteURL $SiteURL -Scope "Web"
}
Else
{
#Iterate through each subsite of the current web
ForEach ($Subweb in $Ctx.Web.Webs)
{
#Call the function recursively
Get-SPOCustomActions -SiteURL $Subweb.url -Scope "Web"
}
}
}
Catch {
write-host -f Red "Error Generating Custom Actions Report!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
$ReportOutput = "C:\Temp\CustomActions.csv"
#Delete the Output Report, if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }
#Call the function
Get-SPOCustomActions -SiteURL $SiteURL -Scope "Site"
รับการดำเนินการแบบกำหนดเองทั้งหมดโดยใช้ PnP PowerShell
หากต้องการดึงการกระทำแบบกำหนดเองทั้งหมด ให้ใช้ PnP PowerShell cmdlet Get-PnPCustomAction
#Variable
$SiteURL = "https://Crescent.sharepoint.com"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get all custom actions
Get-PnPCustomAction -Scope All
คุณสามารถตั้งค่าขอบเขตเป็น "ไซต์" หรือ "เว็บ" เพื่อดึงข้อมูลไซต์คอลเลกชันหรือการดำเนินการแบบกำหนดเองเฉพาะไซต์ได้