Search code examples
powershellmicrosoft-graph-apipowershell-2.0

how to set a usage location to a user in PowerShell using Microsoft-Graph


need a mggraph command-let that helps me to set a usage location to an existing user

I tried this command

$user=get-mguser -userid f75bff42-f7bf-426a-862c-1771ea379b72
$user.usagelocation="IN"
set-mguser -userid f75bff42-f7bf-426a-862c-1771ea379b72 -usagelocation $user.location

-I tried this because we used to do the same in MSOnline

by using this I get an error showing that the command set-mguser is not recognized:

set-mguser : The term 'set-mguser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 set-mguser -userid f75bff42-f7bf-426a-862c-1771ea379b72 -usagelocatio ...

CategoryInfo : ObjectNotFound: (set-mguser:String) [], CommandNotFoundException FullyQualifiedErrorId : CommandNotFoundException


Solution

  • There is no Set-MgUser cmdlet in Microsoft.Graph.Users submodule.

    You need to use Update-MgUser cmdlet.

    $userId = 'f75bff42-f7bf-426a-862c-1771ea379b72'
    $usageLocation = 'IN'
    
    Update-MgUser -UserId $userId -Usagelocation $usageLocation
    

    Documentation:

    Microsoft.Graph.Users cmdlets

    Update-MgUser