Sitecore Powershell script to get nested Item details

Sitecore Powershell script to get nested Item details 


 

$itempath = "web:/sitecore/content/Home"
$AllItems = Get-ChildItem -Path $itempath -Recurse|
          Where-Object { $_.TemplateID -eq "{AEE92059-2C73-4B79-99DB-B9968D680D7D}" -or  $_.TemplateID -eq "{AEE92059-2C73-4B79-99DB-B9968D680D7B}"}
$results = @();
$AllItems | ForEach-Object {      
        $ID =  $_.ID
        $Name =  $_.Name
        $ItemPath =  $_.ItemPath
        $KeyContactFolderPath = "web:"+ $ItemPath + "/Key Contacts"
        $AllKeyContactsItems = Get-ChildItem -Path $KeyContactFolderPath -Recurse|
                                                     Where-Object { $_.TemplateID -eq "{1D9C675E-32CF-42D9-9906-290291AA4D2A}"}
        $AllKeyContactsItems | ForEach-Object {  
                    $KeyContactRegionItemID = $_.ID;
                    $KeyContactRegionItemName = $_.Name;
                    $KeyContactRegionItemPath = $_.ItemPath;
                    $RelatedPersons = $_."Related Person";
                    $split = $RelatedPersons.Split('|');
                    foreach ($t in $split)
                    {
                        $path = "$t";
                        if($t -ne "")
                        {
                            if(($RelatedPersonItem = Get-Item -Path web: -Id $t -ErrorAction SilentlyContinue))
                            {
                                $properties = @{
                                            ID  = $ID
                                            Name = $Name
                                            ItemPath = $ItemPath
                                            KeyContactRegionItemID = $KeyContactRegionItemID;
                                            KeyContactRegionItemName = $KeyContactRegionItemName;
                                            KeyContactRegionItemPath = $KeyContactRegionItemPath;
                                            RelatedPersonID = $t
                                            RelatedPersonName = $RelatedPersonItem.Name
                                            }
                                $results += New-Object psobject -Property $properties
                            }
                        }
                    }
                 }
}
if($results.Count -gt 0) {
    $results |
        Show-ListView -Property @{Label="ID"; Expression={$_.ID} },
                @{Label="Item Name"; Expression={$_.Name} },
                @{Label="Item Path"; Expression={$_.ItemPath} },
                @{Label="Key Contact Region Item ID"; Expression={$_.KeyContactRegionItemID} },
                @{Label="Key Contact Region Item Name"; Expression={$_.KeyContactRegionItemName} },
                @{Label="Key Contact Region Item Path"; Expression={$_.KeyContactRegionItemPath} },
                @{Label="Related Person ID"; Expression={$_.RelatedPersonID} },
                @{Label="Related Person Name"; Expression={$_.RelatedPersonName} }
    } else {
        Show-Alert "There are no Data."
    }



Comments

Popular posts from this blog

Sitecore Powershell Extension (SPE)