kwizcom banner advertisement

Find All Custom Actions in SharePoint using PowerShell

PowerShell to Get Custom Actions in SharePoint
Custom actions may be deployed to site, web or list scopes. Here is a PowerShell script to list all custom actions from the given web scope.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Site variable

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)"
        write-host -f Yellow "No Custom Actions Found!"
} Catch {
    Write-Host -ForegroundColor Red "Error:" $_.Exception.Message

PowerShell to Find All Custom Actions in a Site Collection
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
$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}
This script gets all custom actions from the given site collection's site, web and list scopes and exports them to a CSV file.
Find All Custom Actions in SharePoint using PowerShell Find All Custom Actions in SharePoint using PowerShell Reviewed by Salaudeen Rajack on July 10, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.