Get Azure AD Group PowerShell with Active Directory Management

Author

Reads 826

Free stock photo of administrative work, business, busy
Credit: pexels.com, Free stock photo of administrative work, business, busy

To manage Azure AD groups using PowerShell, you need to connect to Azure AD with the AzureAD module, which can be installed from the PowerShell Gallery.

Azure AD groups are a fundamental component of Azure AD, allowing you to organize and manage users, devices, and applications.

With the AzureAD module, you can use cmdlets like Get-AzureADGroup and Set-AzureADGroup to retrieve and modify group properties.

These cmdlets provide a powerful way to manage Azure AD groups and are a crucial part of any Azure AD management workflow.

Getting Started

To get started with Azure AD Group PowerShell, you'll first need to install the AzureAD PowerShell module.

You can do this by running the command Install-Module -Name AzureAD in your PowerShell console.

Make sure your PowerShell console is set to use the AzureAD module by running the command Import-Module -Name AzureAD.

To connect to your Azure AD, run the command Connect-AzureAD.

You'll be prompted to enter your Azure AD credentials to authenticate the connection.

Once connected, you can verify the connection by running the command Get-AzureADTenantDetail.

This will display information about your Azure AD tenant, including its ID and display name.

Using Cmdlets

Credit: youtube.com, Connecting to Azure AD in PowerShell

You can use PowerShell to get the group membership of Office 365 users by installing and connecting the Azure Active Directory module.

To retrieve the list of Microsoft 365 groups a user is a member of, run the cmdlets Connect-AzureAD and Get-AzureADUserMembership with the ObjectId of the user.

Before running any cmdlet, you must first run the Connect-AzureAD command to authenticate to your Azure AD tenant.

Alternatively, you can run the command from Azure Cloud Shell, a browser-based command line interface that supports PowerShell and Azure CLI (Bash) commands.

The Get-AzureADGroup cmdlet is part of the AzureAD module, which you must install and import to run the command from your computer.

To get an Azure AD group, you can use the Get-AzureADGroup cmdlet with the All parameter, which takes a boolean value of $true or $false.

If you set All to $true, the command returns all groups in the Azure AD tenant.

Credit: youtube.com, Azure AD Users and Groups Portal Powershell and CLI in 10 Mins

If you set All to $false, the command returns the number of objects specified in the Top parameter.

Here are the basic parameters of the Get-AzureADGroup cmdlet:

  • All: a boolean value of $true or $false
  • Top: the number of objects to return
  • Filter: a filter statement to determine which objects are returned

You can also use the SearchString parameter to specify a search string, which affects the groups returned by the command.

Additionally, you can use the ObjectId parameter to specify the Id of the group you want to return.

To return all Azure AD groups, run the command Get-AzureADGroup with the All parameter set to $true.

To return a single Azure AD group, you can use the ObjectId parameter to specify the Id of the group.

Auditing Active Directory Changes

Auditing Active Directory changes is a crucial step in maintaining the security and integrity of your Azure AD groups. You can utilize AdminDroid's chart feature to visualize the count of membership changes by selecting by Added/Removed user.

To filter the group membership changes and their count over a specified time range, you can use the time filter at your convenience. This allows you to focus on the changes that occurred during a specific time period.

Managing Active Directory

Credit: youtube.com, Users and Groups in Azure Active Directory | Manage users and groups using GUI and AAD PowerShell

Managing Active Directory is a crucial task for any organization, and Azure AD PowerShell makes it a breeze. You can connect to Azure Active Directory with Connect-AzureAD and authenticate to your Azure AD tenant.

To list down groups, you can use the Get-AzureADGroup command with the SearchString parameter, as shown in the example "Get-AzureADGroup -SearchString "sg"". This will list down any group containing "sg" in the Display name field.

You can filter groups in a hybrid environment by using the DirSyncEnabled attribute. For instance, Get-AzureADGroup -Filter 'DirSyncEnabled eq true' | select ObjectId,DisplayName,LastDirSyncTime will list down groups that are synced from on-premises Active Directory.

To view group memberships, use the Get-AzureADGroupMember cmdlet with the ObjectId parameter. For example, Get-AzureADGroupMember -ObjectId 2a11d5ee-8383-44d1-9fbd-85cb4dcc2d5a will list down the members of the group with the specified ObjectId.

You can add members to a group using the Add-AzureADGroupMember cmdlet. For instance, Add-AzureADGroupMember -ObjectId 2a11d5ee-8383-44d1-9fbd-85cb4dcc2d5a -RefObjectId a6aeced9-909e-4684-8712-d0f242451338 will add the user with the specified RefObjectId to the group with the specified ObjectId.

In a hybrid environment, security groups are mainly synced from on-premises AD. However, you can create cloud-only groups using the New-AzureADGroup cmdlet. For example, New-AzureADGroup -DisplayName "REBELADMIN Sales Team" -MailEnabled $false -MailNickName "salesteam" -SecurityEnabled $true will create a cloud-only security group called "REBELADMIN Sales Team".

Reporting and Exporting

Credit: youtube.com, Get-MgUser – Find and Export Azure AD Users with PowerShell

You can use PowerShell to create reports on Azure AD groups and their members. To report members of multiple Azure AD groups, you can save the output of Get-AzureADGroup to a variable and then use a ForEach loop to return all members of each group.

The script can be run in PowerShell ISE, but you need to run the Connect-AzureAD command before running the script. The command returns the group membership of the groups returned by the Get-AzureADGroup command.

You can customize the report by including only the properties you need, such as DisplayName and UserPrincipalName, by using the Format-Table command or piping the output to a Select-Object command.

To export the output to a CSV file, you can modify the script to include the Export-Csv cmdlet. This will save the report to a CSV file, making it easy to view and analyze in applications like Microsoft Excel.

Here are some examples of how to export Azure AD group members to a CSV file:

  • To export all members of a specific group to a single CSV file, you can use the script below.
  • To bulk export all Microsoft Entra ID groups and their members to a CSV file, you can use the script below.

These scripts create a single CSV file that includes the group members' details, such as Name, UserPrincipalName, Alias, UserType, and AccountEnabled. The CSV file can be opened in an application like Microsoft Excel to view the results.

Filtering and Searching

Credit: youtube.com, Get Active Directory and Azure Users by Department PowerShell

To filter Azure AD groups in PowerShell, you can use the Filter parameter in the Get-AzureADGroup command. This parameter allows you to return groups that meet specific criteria.

To use the Filter parameter, you can specify a string that includes the filtering criteria, such as "InfraSOS" in the DisplayName. This will return all groups that include "InfraSOS" in their display name.

You can also use the SearchString parameter to search for groups that meet specific criteria. The SearchString parameter is similar to the Filter parameter, but it returns groups that include the specified string anywhere in their properties, not just in the DisplayName.

To access Azure Cloud Shell and run these commands, you need to open shell.azure.com and sign in with your Azure account. Make sure to select PowerShell when the Cloud Shell loads.

Display Details

You can find the details of a specific group in Microsoft Entra ID by using its display name in a PowerShell command. To do this, you'll need to know the display name of the group you're interested in, like "Sales UK" in our example.

Credit: youtube.com, Enable Azure AD Groups for GroupWriteback v2 using MS Graph Powershell

To get extended information about the members of a specific group, you can use the PowerShell cmdlet Get-MgGroupMember. This cmdlet will give you detailed information about the members of the group.

You can display information about all the Microsoft Entra ID groups in PowerShell output, and even export it to a CSV file for further analysis. Remember, all the information you can display on the PowerShell console can also be exported to a CSV file.

Rosemary Boyer

Writer

Rosemary Boyer is a skilled writer with a passion for crafting engaging and informative content. With a focus on technical and educational topics, she has established herself as a reliable voice in the industry. Her writing has been featured in a variety of publications, covering subjects such as CSS Precedence, where she breaks down complex concepts into clear and concise language.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.