Certain fields of mguser update arent working and I am unsure why.

Nicolas Odorico 20 Reputation points
2024-05-13T15:24:18.1066667+00:00

$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

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,865 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 142.8K Reputation points MVP
    2024-05-13T15:54:13.79+00:00

    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
    

0 additional answers

Sort by: Most helpful