Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE ::How To Read Column From CSV File In PowerShell?
In this article, we are going to learn how to read a column from CSV file in PnP PowerShell.
Use Case
While working with PowerShell scripting we used to have requirement to read column values from csv file and perform some operation. like bulk update item in SharePoint, Create site collection etc.
Here is the sample CSV file we have – SitesToCreate.csv
Columns – Site Title,SiteURL,Template,StorageQuota,Owner,TimeZone,LocId
Script to read CSV file
Using below powershell script code we can read the columns from csv file (SitesToCreate.csv)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
PS C:\Peter\ReadCSV> .\ReadCSV.ps1 [parameter(Mandatory=$false)][string]$CsvFilePath = ".\SitesToCreate.csv" #Loading CSV file $csvItems = Import-Csv $CsvFilePath foreach($Item in $csvItems) { Write-Host "Site Name-" $Item.SiteName -ForegroundColor Green Write-Host "SiteURL-" $Item.SiteURL -ForegroundColor Green Write-Host "Site Template-" $Item.Template -ForegroundColor Green Write-Host "Site StorageQuota-" $Item.StorageQuota -ForegroundColor Green Write-Host "Site Owner-" $Item.Owner -ForegroundColor Green Write-Host "Site TimeZone-" $Item.TimeZone -ForegroundColor Green Write-Host "Site Location Id-" $Item.LocId -ForegroundColor Green } |
Result-
PS C:\Peter\ReadCSV> .\ReadCSV.ps1
SiteName : Devlopment Site
SiteURL : https://advanced365app.sharepoint.com/sites/DevTest
Template : STS#0
StorageQuota : 100
Owner : Peter@advanced365app.onmicrosoft.com
TimeZone : 4
LocId : 1033
SiteName : UAT Site
SiteURL : https://advanced365app.sharepoint.com/sites/UATSite
Template : STS#0
StorageQuota : 100
Owner : Peter@advanced365app.onmicrosoft.com
TimeZone : 4
LocId : 1033
Print article | This entry was posted by Peter on April 8, 2022 at 4:07 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |