Need to grab those properties before you can select them
Example:
Get-MgUser -UserId $existingUser -Property JobTitle, Department, City, StreetAddress, Mail| Select-Object JobTitle, department, City, StreetAddress, Mail
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
$csvData = $csv | Select "User principal name","Title", "Department", "City", "StreetAddress", "Reporting managers"
foreach($user in $csvData){
$userPrincipalName = $user."User principal name"
$existingUser = Get-MgUser -Filter "userPrincipalName eq '$userPrincipalName'" | Select-Object -ExpandProperty Id
Get-MgUser -UserId $existingUser | Select-Object JobTitle, department, City, StreetAddress, Mail
if($existingUser){
$reportingManager = $user."Reporting managers"
$manager = Get-MgUser -Filter "DisplayName eq '$reportingManager'" | Select-Object -ExpandProperty Id
$newManager = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/$manager"
}
Set-MgUserManagerByRef -UserId $userPrincipalName -BodyParameter $NewManager
$userUpdates = @{
Department = $user.'Department'
JobTitle= $user.'Title'
City = $user.'City'
StreetAddress = $user.'StreetAddress'
}
Write-Output $userUpdates
Update-MgUser -UserId $existingUser -BodyParameter $userUpdates
}
}
It does have a correct $csv,
However when I go to run this script only the manager, and job title will update,
The writeoutput $userUpdates has the correct information that I want to update the user with but still both city, department, streetaddress are all blank when I got and check a specific user
Need to grab those properties before you can select them
Example:
Get-MgUser -UserId $existingUser -Property JobTitle, Department, City, StreetAddress, Mail| Select-Object JobTitle, department, City, StreetAddress, Mail