skip to Main Content

I need the accountenabled property to further the script, but for Get-MgUser.

I need to modify the current script that have Msol or AzureAD cmdlets to MSGraph, but I can’t find anything so i don’t throw out the script and create a new one.

Get-AzureADUser -Filter "UserPrincipalName eq '$UserPrincipalName'" | select ObjectId, AccountEnabled

2

Answers


  1. To retrieve the AccountEnabled property using the Get-MgUser cmdlet, you can try the following PowerShell script

    $UserPrincipalName = "<user-principal-name>"
    $user = Get-MgUser -Filter "userPrincipalName eq '$UserPrincipalName'"
    $AccountEnabled = $user.AccountEnabled
    
    Login or Signup to reply.
  2. In order to get he users with account enabled in microsoft graph check the following:

    Install-Module Microsoft.Graph -AllowClobber -Force

    Connect-MgGraph -Scopes 'User.Read.All'

    • The following property must be used with filter im Microsft graph as by default its not present in commandlets:

    Get-MgUser -Filter 'accountEnabled eq true' -All

    Result:

    Id                                   DisplayName                                           Mail                                           UserPrincipalName                       
    --                                   -----------                                           ----                                           -----------------                       
    xx09e Admin                                                 adminxxOnMicrosoft.com          
    

    It doesn’t have the particular property account enabled but can be filtered

    enter image description here x

    Reference: Get-MgUser (Microsoft.Graph.Users) | Microsoft Learn

    In azure ad commandlets we get those properties :

    Get-AzureADUser | select ObjectId, AccountEnabled

    ObjectId                             AccountEnabled
    --------                             --------------
    xxx4037d27e015c               False
    db5ccaa9xxx0740409e           True
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search