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

No comments:

Post a Comment