After importing a CSV file, I create a hashtable of the variables that will be used in a simple command line.
Problem is that when I import the CSV files, the headers are transposed; instead of it being a table with various headers, it is different. My code is:
$Import = Import-Csv "File\path\input.csv"
foreach ($user in $import) {
$msolparams = @{
UPN = $user.SamAccountName + "@company.com"
Title = $user.JobTitle
Deparment = $user.DepartmentTitle
Displayname = $user.Pname + "," + " " + $user.Plname
Location = $user.location}
Set-MsolUser -UserPrincipalName $msolparams.UPN -Title $msolparams.Title -Department $msolparams.Department -DisplayName $msolparams.Displayname}
After checking the $import
variable with the CSV file input, the hashtable headers come out as so:
SamAccountName : kodak.black
Location : Central
JobTitle : Title
DepartmentTitle : Department
Pname : Kodak
Plname : Black
instead of
SamAccountName Location JobTitle DepartmentTitle Plname Pname
And because of this it does not grab values from the headers properly and gives the error Cannot find MsolUser .
Also you cannot use | ft
anywhere in the variables because the code will error out and will stop.
Please let me know what you think