Tuesday, 4 May 2021

How to read list data from file, using Sitecore PowerShell script

Challenge:

There were scenario, where I was trying to get list of strings from text file and tried as below

[string[]]$ItemIdList = Get-Content -Path 'D:\ItemIds.txt'

but getting issue as file not found.


Approach to resolve:


With below lines of script, trying to first upload at temp/upload path (it will create directories if not exist).

And then reading list of strings from text file.

$dataFolder = [Sitecore.Configuration.Settings]::DataFolder
$tempFolder = $dataFolder + "\temp\upload"
$filePath = Receive-File -Path $tempFolder -overwrite'
[string[]]$ItemIdList = Get-Content -Path $filePath

Friday, 23 April 2021

How to get list of items with linked items using Sitecore PowerShell script ?

I was trying to get list of items with directly linked items using PowerShell script.
Since from Sitecore content editor at a time can see linked items only for individual items, so thought to share with all.

Below is the script hope, this will help

    
$allImages = Get - ChildItem - Path 'master:/sitecore/media library/Images' - recurse
$results = @();
$allImages | ForEach - Object {
    $sproperties = @{
        SID = $_.ID
    }

    $referer = Get - ItemReferrer - ID  $sproperties.SID
    $properties = @{
        Name = $_.Name
       ID = $_.ID
       Path = $_.ItemPath
       LinkedItemIds = $referer.ID
    }
    $results += New - Object psobject - Property $properties
}

$results | Select - Object - Property Name, Path, LinkedItemIds