title: Azure AD - Get User Role - PowerShell
body: <p>Question, as I have a complete script that scraps info of users from Azure AD.</p>
  <p>However, one thing that I am having trouble with is to get &quot;User Role of any user&quot;</p>
  <p>The goal is to check if the logged in user is &quot;Global Administrator&quot;, if not, then Exit the script.</p>
  <pre><code>Write-Host &quot;Connect to AzureAD&quot; -ForegroundColor Yellow
  Connect-AzureAD
  
      Write-Host &quot;[] Validating Azure signed-in User's Role ... &quot; -ForegroundColor Yellow
      
      $currentUser = (Get-AzureADUser -ObjectId (Get-AzureADCurrentSessionInfo).Account.Id)    
      $currentUser
      
      $MyName = $currentUser.DisplayName
      Write-Host &quot;[✔] Welcome: $MyName&quot; -ForegroundColor Green
      
      
      
      Write-Host &quot;Your role is: &quot;
  </code></pre>
  <p>Tried to use the following two below, with no luck</p>
  <p><strong>Get-AzureADCurrentSessionInfo</strong></p>
  <p><strong><a href="https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureaddirectoryrolemember?view=azureadps-2.0" rel="nofollow noreferrer">Get-AzureADDirectoryRoleMember</a></strong></p>
  <p>Can someone help with that please.</p>
  <p>For ref: Screenshot from the GUI</p>
  <p><a href="https://i.stack.imgur.com/DTgVT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTgVT.png" alt="Azure Role GUI" /></a></p>
  <p>As there is this script that can be used and integrated with my goal above</p>
  <pre><code>$role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Global Administrator'}
  Get-AzureADDirectoryRoleMember -ObjectId $role.ObjectId 
  </code></pre>
  <p>Thanks</p>