Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to find item list field which has non guid value in link

With this powershell command you will be to find item list field which has non guid value in link.

 

Import-Function -Name ConvertTo-Xlsx

$sourcePath = Show-Input "Please provide full path of source folder like /sitecore/content/projectName/Home/Home"  -DefaultValue ''

if($sourcePath -ne '')
{
    $rootPath = 'master:'+$sourcePath    
    $itemsToProcess = Get-ChildItem -Path $rootPath -Recurse 

    #$itemsToProcess 
    $list = @()
    foreach($item in $itemsToProcess) 
    {
      # $item 
        $path = "master:"+$item.Paths.FullPath 
       $fields =  Get-ItemField -Path $path -IncludeStandardFields -ReturnType  Field | Where-Object { $_.Type -eq "Multilist" -or $_.Type -eq "Treelist" -or $_.Type -eq "TreelistEx" -or $_.Type -eq "Droplink"  -or $_.Type -eq "Droplist"}
      # $fields
        foreach( $field in $fields)
        {
            $filedvalueRaw = $item.Fields[$field.Name].Value
            
            if($filedvalueRaw -ne "")
            {
                $filedvalues = $filedvalueRaw.Split("|")
          
                foreach($filedvalue in $filedvalues)
                {
                    $isGuid =  $filedvalue -match ("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$") 
                    #$isGuid
                    if( $isGuid -eq $False)
                    {
                        $filedWithWrongValue = [PSCustomObject]@{
                            ItemName     = $item.Name
                            ItemID = $item.ID
                            ItemPath    = $item.Paths.FullPath
                            FieldName    = $field.Name
                            FiledValue = $filedvalue
                        }
                        $list += $filedWithWrongValue
                        #$filedvalue
                        #$item
                    }

                }    
            }
            
        }
    }
    
    [byte[]]$outobject =  $list | ConvertTo-Xlsx 
    Out-Download -Name "report-Item-list-has-nonguid-value-in-link.xlsx" -InputObject $outobject

}








Posted: 23/04/2022 5:25:37 p.m. by Gitesh Shah | with 0 comments