Run Powershell using a CSV list as input - Fabian Neve

About SharePoint, Javascript, PowerShell, and other technical stuff

Friday, October 23, 2015

Run Powershell using a CSV list as input

Let's assume you have a CSV list with several columns which you want to use as variables. Something like that:

Hans Muster,,hmuster
Frauke Peters,,fraukepeters
Hugo Schönbächler,,teh_hugo

Notice, the data is separated by commas (,), not semicolons, not tabs. This is relevant!

Then save the csv as eg. C:\temp\users.csv.

Now comes the powershell script:

$csv = Import-Csv C:\temp\users.csv
foreach ($line in $csv) {
$name = $line.Name
$mail = $line.eMail
$account = $line.Account

Inside the brackets { } you put your script after the variables you defined in the first lines. Done.