Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, August 14, 2024

Powershell script to read the groups using Get-MgGroup

# Step 1: Define the client credentials

$clientId= "<<client id>>"

$tenantId= "<<tenant id>>"

$clientSecret = ConvertTo-SecureString "<<client secret>>" -AsPlainText -Force


 # Step 2: Create the PSCredential object

$credential = New-Object System.Management.Automation.PSCredential($clientId, $clientSecret)


Connect-MgGraph -Credential $credential -TenantId $tenantId


# Retrieve all groups with preferred properties

$groups = Get-MgGroup -All -Property Id, DisplayName, OnPremisesSyncEnabled, mail


# Define the output file path

$excelFilePath = "C:\AzureGroupsExport\AzureADGroups.xlsx"


# Export the groups to Excel

$groups | Select-Object Id, DisplayName, OnPremisesSyncEnabled, mail | Export-Excel -Path $excelFilePath -WorksheetName "AzureADGroups" -AutoSize


# Notify the user

Write-Output "Groups have been exported to $excelFilePath"

Tuesday, January 19, 2021

Azure AD Powershell command to query group with DirSyncEnabled attribute

There are times you want to know synched or cloud only groups.

Command to search synched groups - 

Get-AzureADGroup -All $true | where-Object {$_.DirSyncEnabled -eq $TRUE}

Command to search cloud only groups - 

Get-AzureADGroup -All $true | where-Object {$_.DirSyncEnabled -eq $NULL}

Funny enough that DirSyncEnabled attribute contains "TRUE" (if it's synched group) "NULL" (if cloud only)

Thanks

Siva Pokuri.

Thursday, April 25, 2019

Tips: Azure AD B2B user UserPrincipalName(UPN) update

Issue:

Trying to update the UserPrincipalName (UPN) of B2B user to some public domain email address like siva@gmail.com in Azure AD tenant and results below error message.

Error message - "Property userPrincipalName is invalid"



Solution:

Make sure create/update user UPN with verified domain names in Azure AD tenant.

Thanks
Siva Pokuri.