This hasn't been tested! Also, I don't think the Get-MsolUser will return all the stuff you need.
# column names for input and output
$props = [ordered]@{
"Employee Id" = "The USER OBJECT property name"
"First Name" = "The USER OBJECT property name"
"Last Name" = "The USER OBJECT property name"
"Known As" = "The USER OBJECT property name" # not sure what AD property this is
"Work Email" = "The USER OBJECT property name"
"Company" = "The USER OBJECT property name"
"Location" = "The USER OBJECT property name"
"Department" = "The USER OBJECT property name"
"Job Role" = "The USER OBJECT property name"
"Manager Email" = "The USER OBJECT property name" # I don't think this is returned by MSOLUser
}
$OutRow = [ordered]@{}
$SetProps = @{} # used for splatting in set-msoluser/set-aduser
Import-Csv "some-file-name.csv" |
ForEach-Object {
$row = $_ # $_ is used in a later, nested, ForEach-Object
$u = Get-MsolUser -UserPrincipalName $row."Work Email" # I think you'll have to use the Get-ADUser to get some of the properties
if ($u) {
# check if the user was found
$OutRow["UserPrincipalName"] = $u."UserPrincipalName" # This wasn't a column in the inout CSV and the email may not be this users UPN
$props.GetEnumerator() |
ForEach-Object {
# the USER the CSV value
if ($u.($_.Value) -ne $row.($_.KEY )) {
$OutRow[$_.Key] = $row.($_.value)
$SetProps[$_.Value] = $row.($_.Value)
}
else {
$OutRow[$_.Key] = ""
}
}
Set-MsolUser @SetProps # update user
[PSObject]$OutRow
$OutRow.Clear() # remove contents of hash
$SetProps.Clear()
}
} | Export-Csv "some-other-file-name.csv" -NoTypeInformation