3

I am trying to generate report using powershell. I am getting results but when I tried to download report using powershell report dialog box throwing error as shown in below screenshot

enter image description here

Please see below code that I wrote to generate report, my Sitecore version is Sitecore 9 update 2 and powershell version is 4.7.2

$startPath = "master:/sitecore/content/Home"
Write-Host "Search started $(Get-Date -format 'u')"   
$linkProvider = [LM.Lightcore.Links.LinkProvider]::new()
$urlOptions = [Sitecore.Links.UrlOptions]::new();
$list = [System.Collections.ArrayList]@()

$itemsToProcess = Get-ChildItem $startPath -Language * -Recurse

if($itemsToProcess -ne $null) {

    $itemsToProcess | ForEach-Object { 
         $match = 0;
         foreach($field in $_.Fields) {
                 if($field -match '.*__SearchText*') {
                      $item = Get-Item ("web:" + $_.ID)
                     $info = [pscustomobject]@{
                         "FullPath"=$_.Paths.FullPath
                         "ItemUrl"=$linkProvider.GetItemUrl($item, $urlOptions)

                     }
                     [void]$list.Add($info)
             }
         }
     }

}

Write-Host "Search ended $(Get-Date -format 'u')"

Write-Host "Items found: $($list.Count)"

$list | Show-ListView  

Close-Window

Thanks Rishi

1
  • Add full stack trace of the exception instead of partial screenshot
    – Marek Musielak
    Commented Dec 14, 2021 at 9:55

1 Answer 1

1

This comes due to the old version of PowerShell i.e. 4.7 which doesn't have proper support for pscustomobject. Either upgrade version to at least 5.1 or be specific when calling to show-listview i.e. give actual field name to show in report like show-listview -property FullPath, ItemUrl.

Hope it gives you an idea of the resolution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.