Skip to main content

Export Pdf list via Sitecore PowerShell Extension

This Sitecore PowerShell utility export a list of Pdfs for specified location 

$FilePath = "master:" + (Get-Item .).Paths.Path

Import-Function -Name ConvertTo-Xlsx

$DownloadReport = 1

$resultObj = @()

$PdfList = Get-childItem -Path $FilePath -Recurse | Where-Object { $_.TemplateName -eq "Pdf"}

$ItemReferrerList = ""

if( $PdfList ){

    $PdfList | ForEach-Object {

        ######Get-ItemReferrer Start

        $ItemArray = @()

        $ItemReferrer = Get-ItemReferrer -ID $_.ID | Where-Object { $_.Name -ne "Admin" -and $_.ItemPath -like "/sitecore/content/*" } | Select-Object -Property ID,Version

        If( $ItemReferrer ){

            $ItemReferrer | ForEach-Object {

             $item = Get-Item -Path master: -ID $_.ID

             $latestVersion = $item.Versions.Count

                if( $_.ID -and $_.Version -eq $latestVersion ){

                    $ID = $_.ID

                    $ItemArray += $ID

                }

            }

            If($ItemArray){

                $ItemReferrerList = $ItemArray -join "|"

            }

        }

        #######Get-ItemReferrer End

        $MediaObj = @{

                ID = $_.ID

                Name =  $_.Name

                UpdatedDate =  $_.__Updated

                SitecoreItemPath = $_.ItemPath  

                ReferencePagesID = $ItemReferrerList

        }

        $resultObj += New-Object psobject -Property $MediaObj

}

#$resultObj | Format-Table ID, Name, SitecoreItemPath, UpdatedDate, ReferencePagesID

if($DownloadReport -eq 1){

        [byte[]] $XLData = $resultObj | Select-Object -Property ID, Name, SitecoreItemPath, UpdatedDate, ReferencePagesID  | ConvertTo-Xlsx

        Out-Download -Name "PdfReport.xlsx" -InputObject $XLData    

    }

}else{

    Write-Host "No Pdf at this location"

    Show-Alert "No Pdf at this location"

}

Review this post to understand how to add PowerShell script in context menu

add-powershell-script-to-the-context-menu



Comments

Popular posts from this blog

Docker Desktop service is not running, would you like to start it?

Bellow message appear while restarting Windows laptop having Docker Desktop installed. Docker Desktop service is not running, would you like to start it? Windows will ask you for elevated access. During online search, we found below solution on stackOverflow which worked for us.  Docker: Service is not running. Windows will ask you for elevated access   Please follow this solution. Hope this helps.

Sitecore Item Bucket

Item buckets How to Create Item Buckets in Sitecore CMS How to Create Custom Item Bucket Rules in Sitecore CMS How to Configure Item Bucket Paths in Sitecore CMS How to Make Custom Bucket Structure in Sitecore - Brimit Blog Bucketing Strategies Item Buckets and URLs How to use Sitecore Bucketing Feature in powerful way?

Sitecore Compatibility

 Sitecore Compatibility Sitecore compatibility table for Sitecore XP 9 and later Sitecore compatibility table for Sitecore CMS 6.0 – XP 8.2.7 Solr compatibility table Sitecore Product Support Lifecycle Sitecore modules compatibility table for Sitecore XP