PowerShell kullanarak SharePoint'teki Tüm Özel Eylemleri Bulun


SharePoint'te Özel Eylemler Almak için PowerShell

Özel eylemler siteye, web'e veya liste kapsamlarına dağıtılabilir. Belirtilen web kapsamındaki tüm özel eylemleri listeleyen bir PowerShell betiği burada verilmiştir.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Site variable
$SiteURL="https://intranet.crescent.com"

Try {
    #Get the Web
    $Web = Get-SPWeb $SiteURL
 
    #Get All Custom Actions of the web
    $CustomActions = $web.UserCustomActions

    If($CustomActions -ne $Null)
    {
        #Get custom action
        ForEach($CustomAction in $CustomActions)
        {
            Write-Host -f Green "Custom Action Title: '$($CustomAction.Title)' ID: $($CustomAction.ID)"
        }
    }
    Else
    {
        write-host -f Yellow "No Custom Actions Found!"
    } 
} Catch {
    Write-Host -ForegroundColor Red "Error:" $_.Exception.Message
}

Site Koleksiyonundaki Tüm Özel Eylemleri Bulmak için PowerShell


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to get custom actions from given scope
Function Get-CustomActions([Microsoft.SharePoint.SPUserCustomActionCollection]$UserCustomActionCollection, [string] $ScopeReference, [string] $ReportOutput)
{
        $CustomActionsData = @()
        ForEach($CustomAction in $UserCustomActionCollection)
        {
            Write-Host -f Green "`t `t `t Found a Custom Action: '$($CustomAction.Title)' at:" $ScopeReference
            #Get Custom Action Data
            $CustomActionsData += New-Object PSObject -Property @{
                    'Deployed At' = $ScopeReference
                    'Name' = $CustomAction.Name
                    'Title' = $CustomAction.Title
                    '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  

}

#Set Site variable
$SiteURL="https://intranet.crescent.com"
 
$ReportOutput = "C:\Temp\CustomActions.csv"
#Delete the Output Report, if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }
 
#Get the Site Collection
$Site = Get-SPSite $SiteURL

Write-host -f Yellow "Searching Site Scoped Custom Actions at:" $SiteURL
$ScopeReference = "Site Collection:"+$Site.Url
If($Site.UserCustomActions -ne $Null) { Get-CustomActions $Site.UserCustomActions  $ReportOutput}
    
#Iterate through each web (subsite) and Get All custom actions
ForEach ($web in $Site.AllWebs)
{
    Write-host -f Yellow "`t Searching Web Scoped Custom Actions at:" $Web.Url
    
    #Get all lists of the web - Exclude hidden
    $ListCollection = $web.Lists | Where-Object  { ($_.hidden -eq $false)}

    #Call the function to Get custom actions at web
    $ScopeReference = "Web:"+$Web.URL
    If($web.UserCustomActions -ne $null) { Get-CustomActions $web.UserCustomActions $ScopeReference $ReportOutput }

    #Get Custom Actions at List level
    Write-host -f Yellow "`t `t Searching List Scoped Custom Actions at:" $Web.Url
    ForEach($List in $ListCollection)
    {
        $ScopeReference = "List:"+$list.RootFolder.ServerRelativeUrl
        If($List.UserCustomActions -ne $Null) {Get-CustomActions $list.UserCustomActions $ScopeReference $ReportOutput}
    }
}

Bu komut dosyası, belirli site koleksiyonunun site, web ve liste kapsamlarındaki tüm özel eylemleri alır ve bunları bir CSV dosyasına aktarır.

İlgili makaleler