Skip to main content
Version: Next

Group helpers

Requires EXO for DGs and role groups, and Microsoft Graph for Microsoft 365 groups where applicable. For full details and examples, run Get-Help <FunctionName> -Detailed.

For the Entra group membership helpers (Add/Remove for Device, Owner, and User), the first positional argument is the group and the second positional argument is the member identifier. The named-parameter forms still work exactly as before.

User-focused helpers now live in users.md, including Search-EntraUser for guest UPN fragments and other partial matches.

Add-EntraGroupDevice​

Add one or more devices to an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Add-EntraGroupDevice [-GroupName <String>] [-GroupId <String>] [[-DeviceIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
DeviceIdentifier (Device, DeviceName, Id, DeviceId, Name)String[]Device display name or object ID. Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every DeviceIdentifier as an object ID (skip name lookup).NoFalse
PassThruSwitchEmit a status object per device.NoFalse

*Use either GroupName or GroupId.

Examples

"PC1","PC2" | Add-EntraGroupDevice -GroupName "Zero Trust Devices"
Add-EntraGroupDevice "Zero Trust Devices" "PC1" -PassThru

Add-EntraGroupOwner​

Add one or more owners to an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Add-EntraGroupOwner [-GroupName <String>] [-GroupId <String>] [[-OwnerIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
OwnerIdentifier (Owner, UPN, Mail, Id, UserId, Name)String[]User principal name, display name, or object ID. Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every OwnerIdentifier as an object ID (skip name lookup).NoFalse
PassThruSwitchEmit a status object per owner.NoFalse

*Use either GroupName or GroupId.

Examples

"user1@contoso.com","user2@contoso.com" | Add-EntraGroupOwner -GroupName "Project Team"
Add-EntraGroupOwner "Project Team" "user1@contoso.com" -PassThru

Add-EntraGroupUser​

Add one or more users to an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Add-EntraGroupUser [-GroupName <String>] [-GroupId <String>] [[-UserIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
UserIdentifier (User, UPN, Mail, Id, UserId)String[]UPN/display name/object ID, external e-mail for invited guests, plus short identifiers (alias/SamAccountName/UPN prefix). Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every UserIdentifier as an object ID (skip name lookup).NoFalse
PassThruSwitchEmit a status object per user.NoFalse

*Use either GroupName or GroupId.

Add-EntraGroupUser also accepts the first two positional arguments, so this works too:

Add-EntraGroupUser "Project Team" "user1@contoso.com"

Examples

"user1@contoso.com","user2@contoso.com" | Add-EntraGroupUser -GroupName "Project Team"
Add-EntraGroupUser -GroupId "00000000-0000-0000-0000-000000000000" "user1@contoso.com" -PassThru

Copy-EntraGroup​

Clone an Entra group into a new or existing group. By default the cmdlet copies description, owners, and members; dynamic groups are cloned as a static snapshot of their current members.

Syntax

Copy-EntraGroup -SourceGroupName <String> -DestinationGroupName <String> [-SkipMembers] [-SkipOwners] [-SkipDescription] [-PassThru]
Copy-EntraGroup -SourceGroupId <String> -DestinationGroupId <String> [-SkipMembers] [-SkipOwners] [-SkipDescription] [-PassThru]
ParameterTypeDescriptionRequiredDefault
SourceGroupName (Source, From)StringSource group display name.Yes*-
SourceGroupIdStringSource group object ID (use instead of SourceGroupName).Yes*-
DestinationGroupName (Destination, To)StringDestination group display name. If no group with this name exists, a new one is created.Yes*-
DestinationGroupIdStringDestination group object ID (use instead of DestinationGroupName).Yes*-
SkipMembersSwitchDo not copy members.NoFalse
SkipOwnersSwitchDo not copy owners.NoFalse
SkipDescriptionSwitchDo not copy the source description.NoFalse
PassThruSwitchEmit a summary object for the clone operation.NoFalse

*Use the Name pair or the Id pair.

Examples

Copy-EntraGroup -SourceGroupName "GitLab-Prod" -DestinationGroupName "GitLab-Prod-Test"
Copy-EntraGroup -SourceGroupName "GitLab-Prod" -DestinationGroupName "GitLab-Prod-Test" -SkipOwners -PassThru
Copy-EntraGroup -SourceGroupId "00000000-0000-0000-0000-000000000000" -DestinationGroupId "11111111-1111-1111-1111-111111111111" -SkipMembers

Copy-EntraGroupOwner​

Copy owners from one Entra group to another without removing existing owners from the destination.

Syntax

Copy-EntraGroupOwner -SourceGroupName <String> -DestinationGroupName <String> [-PassThru]
Copy-EntraGroupOwner -SourceGroupId <String> -DestinationGroupId <String> [-PassThru]
ParameterTypeDescriptionRequiredDefault
SourceGroupName (Source, From)StringSource group display name.Yes*-
SourceGroupIdStringSource group object ID (use instead of SourceGroupName).Yes*-
DestinationGroupName (Destination, To)StringDestination group display name.Yes*-
DestinationGroupIdStringDestination group object ID (use instead of DestinationGroupName).Yes*-
PassThruSwitchEmit a status object per copied owner.NoFalse

*Use the Name pair or the Id pair.

Examples

Copy-EntraGroupOwner -SourceGroupName "HR" -DestinationGroupName "HR - Test"
Copy-EntraGroupOwner -SourceGroupId "00000000-0000-0000-0000-000000000000" -DestinationGroupId "11111111-1111-1111-1111-111111111111" -PassThru

Export-DistributionGroups​

Export distribution groups and members.

Syntax

Export-DistributionGroups [-DistributionGroup <String[]>] [-All] [-Csv] [-CsvFolder <String>] [-GridView]
[-BatchSize <Int32>] [-Resume] [-CsvPath <String>] [-MaxConsecutiveErrors <Int32>]
ParameterTypeDescriptionRequiredDefault
DistributionGroup (DG, Identity)String[]Group identity (name/alias/SMTP). Pipeline accepted.NoAll DGs
AllSwitchExport every distribution group in the tenant.NoFalse
CsvSwitchForce CSV export.NoFalse
CsvFolderStringDestination for CSV.NoCurrent directory
GridViewSwitchShow the result in Out-GridView instead of returning objects.NoFalse
BatchSizeInt32Number of processed groups before flushing partial CSV output.No25
ResumeSwitchResume from the latest matching CSV in the target folder or from -CsvPath.NoFalse
CsvPathStringExplicit CSV file to resume. When omitted, the most recent matching CSV in the target folder is used.No-
MaxConsecutiveErrorsInt32Stop after this many consecutive group-member retrieval failures.No5

Example

Export-DistributionGroups -DistributionGroup "IT Team" -CsvFolder 'C:\Temp\DGs'
tip

Export-DistributionGroups is also available as Export-DG (alias).

Export-DynamicDistributionGroups​

Export dynamic DGs and evaluated members.

Syntax

Export-DynamicDistributionGroups [-DynamicDistributionGroup <String[]>] [-All] [-Csv] [-CsvFolder <String>] [-GridView]
[-BatchSize <Int32>] [-Resume] [-CsvPath <String>] [-MaxConsecutiveErrors <Int32>]
ParameterTypeDescriptionRequiredDefault
DynamicDistributionGroup (DDG, Identity)String[]Dynamic DG identity. Pipeline accepted.NoAll dynamic DGs
AllSwitchExport every dynamic distribution group in the tenant.NoFalse
CsvSwitchForce CSV export.NoFalse
CsvFolderStringDestination for CSV.NoCurrent directory
GridViewSwitchShow the result in Out-GridView instead of returning objects.NoFalse
BatchSizeInt32Number of processed groups before flushing partial CSV output.No25
ResumeSwitchResume from the latest matching CSV in the target folder or from -CsvPath.NoFalse
CsvPathStringExplicit CSV file to resume. When omitted, the most recent matching CSV in the target folder is used.No-
MaxConsecutiveErrorsInt32Stop after this many consecutive group-member retrieval failures.No5

Example

Export-DynamicDistributionGroups -CsvFolder 'C:\Temp\DynDGs'
tip

Export-DynamicDistributionGroups is also available as Export-DDG (alias).

Export-EmptyEntraGroups​

Export Entra groups with zero members.

Syntax

Export-EmptyEntraGroups [-CsvFolder <String>] [-Csv]
ParameterTypeDescriptionRequiredDefault
CsvFolderStringDestination for the CSV file.NoCurrent directory
CsvBooleanExport the report to CSV. Use -Csv:$false to return objects instead.NoTrue

Examples

# Export every empty Entra group to CSV
Export-EmptyEntraGroups
# Export to a custom folder
Export-EmptyEntraGroups -CsvFolder 'C:\Temp\Groups'

Export-M365Group​

Export Microsoft 365 groups (members/owners).

Syntax

Export-M365Group [-M365Group <String[]>] [-All] [-Csv] [-CsvFolder <String>] [-GridView]
ParameterTypeDescriptionRequiredDefault
M365Group (Group, Identity)String[]Group identity (name/alias/SMTP). Pipeline accepted.NoAll M365 groups
AllSwitchExport every Microsoft 365 group in the tenant.NoFalse
CsvSwitchForce CSV export.NoFalse
CsvFolderStringDestination for CSV.NoCurrent directory
GridViewSwitchShow the result in Out-GridView instead of returning objects.NoFalse

Example

Export-M365Group -M365Group "Project A" -CsvFolder 'C:\Temp\M365'

Get-DynamicDistributionGroupFilter​

Show the simplified filter of a dynamic distribution group.

Syntax

Get-DynamicDistributionGroupFilter -DynamicDistributionGroup <String[]> [-IncludeDefaults] [-AsObject]
ParameterTypeDescriptionRequiredDefault
DynamicDistributionGroup (DDG, Identity)String[]Dynamic DG identity. Pipeline accepted.Yes-
IncludeDefaultsSwitchInclude default EXO filter clauses.NoFalse
AsObjectSwitchReturn as object instead of string.NoFalse

Example

Get-DynamicDistributionGroupFilter -DynamicDistributionGroup "All Mailboxes"
tip

Get-DynamicDistributionGroupFilter is also available as Get-DDGRecipientFilter (alias).

Get-EntraGroupDevice​

Show the Entra groups a device belongs to (Graph scopes: Group.Read.All, Directory.Read.All).

Syntax

Get-EntraGroupDevice [[-DeviceIdentifier] <String>] [-TreatInputAsId] [-GridView]
ParameterTypeDescriptionRequiredDefault
DeviceIdentifier (Device, DeviceName, Id, DeviceId, Name, Identity, DisplayName)StringDevice display name or object ID. Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat the DeviceIdentifier as an object ID (skip name lookup).NoFalse
GridViewSwitchShow details in Out-GridView.NoFalse

Examples

Get-EntraGroupDevice "PC123"
"00000000-0000-0000-0000-000000000000" | Get-EntraGroupDevice -TreatInputAsId -GridView

Get-EntraGroupMembers​

Show the members of an Entra group (users, devices, and other directory objects) (Graph scopes: Group.Read.All, Directory.Read.All).

Syntax

Get-EntraGroupMembers [-GroupName <String>] [-GroupId <String>] [-IncludeDeviceUsers] [-GridView]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName, Name, Identity)StringTarget group display name. Pipeline accepted.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
IncludeDeviceUsersSwitchWhen members are devices, resolve registered owners and users.NoFalse
GridViewSwitchShow details in Out-GridView.NoFalse

*Use either GroupName or GroupId.

Examples

Get-EntraGroupMembers "intune - app - netterm"
"intune - app - netterm" | Get-EntraGroupMembers
Get-EntraGroupMembers -GroupId "00000000-0000-0000-0000-000000000000" -GridView
Get-EntraGroupMembers "intune - app - netterm" -IncludeDeviceUsers
note
  • When -IncludeDeviceUsers is used and the member is a device, the output includes a Device Owners/Users column.
  • If owners and users are identical, the list is shown once; otherwise owners and users are combined in the same column.

Get-EntraGroupUser​

Show the Entra groups a user belongs to (Graph scopes: Group.Read.All, Directory.Read.All).

Syntax

Get-EntraGroupUser [[-UserIdentifier] <String>] [-TreatInputAsId] [-GridView]
ParameterTypeDescriptionRequiredDefault
UserIdentifier (User, UPN, Mail, Id, UserId, DisplayName, Identity)StringUPN/display name/object ID, external e-mail for invited guests, plus short identifiers (alias/SamAccountName/UPN prefix). Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat the UserIdentifier as an object ID (skip name lookup).NoFalse
GridViewSwitchShow details in Out-GridView.NoFalse

Examples

Get-EntraGroupUser "user@contoso.com"
"00000000-0000-0000-0000-000000000000" | Get-EntraGroupUser -TreatInputAsId -GridView

Get-RoleGroupsMembers​

List Exchange Online role groups and members.

Syntax

Get-RoleGroupsMembers [-AsTable] [-GridView]
ParameterTypeDescriptionRequiredDefault
AsTableSwitchShow formatted table output.NoFalse (objects)
GridViewSwitchShow results in Out-GridView.NoFalse

Example

Get-RoleGroupsMembers -AsTable

Get-UserGroups​

Show the groups (DGs/M365) a user/contact/group belongs to.

Syntax

Get-UserGroups -UserPrincipalName <String> [-GridView]
ParameterTypeDescriptionRequiredDefault
UserPrincipalName (User, Identity, UPN)StringUser/contact/group identity.Yes-
GridViewSwitchShow details in Out-GridView.NoFalse

Output

  • Default output columns: GroupName, GroupMail
  • With -GridView: additional details are included (description, type, ID, etc.)

Get-UserGroups first tries the Exchange recipient view for regular mailbox users. If that lookup is not available, it falls back to Microsoft Graph so Entra guest users can still be inspected from PowerShell.

Breaking Change (version 1.2.0 or newer)

Get-UserGroups now returns GroupName and GroupMail instead of Group Name and Group Mail. Update any legacy filters/scripts accordingly, for example: use $_.GroupName instead of $_.'Group Name'.

Examples

Get-UserGroups -UserPrincipalName 'user@contoso.com'
Get-UserGroups 'user@contoso.com' | Where-Object { $_.GroupName -like '*portion-of-group-name*' }

New-EntraSecurityGroup​

Create a new Entra security group with a generated mail nickname unless one is supplied.

Syntax

New-EntraSecurityGroup -GroupName <String> [-Description <String>] [-MailNickname <String>] [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (DisplayName, Name)StringDisplay name of the new security group.Yes-
DescriptionStringOptional group description.No-
MailNicknameStringOptional mail nickname. When omitted, a sanitized value is generated from GroupName.NoGenerated
PassThruSwitchReturn the created group object.NoFalse

Examples

New-EntraSecurityGroup -GroupName "Sec - Finance"
New-EntraSecurityGroup -GroupName "Sec - Finance" -Description "Finance security group" -PassThru

Remove-EntraGroupDevice​

Remove one or more devices from an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Remove-EntraGroupDevice [-GroupName <String>] [-GroupId <String>] [[-DeviceIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
Remove-EntraGroupDevice [-GroupName <String>] [-GroupId <String>] -ClearAll [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
DeviceIdentifier (Device, DeviceName, Id, DeviceId, Name)String[]Device display name or object ID. Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every DeviceIdentifier as an object ID (skip name lookup).NoFalse
ClearAllSwitchRemove all device members from the group (users and other objects are not removed). Prompts for confirmation.NoFalse
PassThruSwitchEmit a status object per device.NoFalse

*Use either GroupName or GroupId.

Examples

"PC1","PC2" | Remove-EntraGroupDevice -GroupName "Zero Trust Devices"
Remove-EntraGroupDevice "Zero Trust Devices" "PC1" -PassThru
Remove-EntraGroupDevice -GroupName "Zero Trust Devices" -ClearAll
Remove-EntraGroupDevice -GroupName "Zero Trust Devices" -ClearAll -WhatIf

Remove-EntraGroupOwner​

Remove one or more owners from an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Remove-EntraGroupOwner [-GroupName <String>] [-GroupId <String>] [[-OwnerIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
Remove-EntraGroupOwner [-GroupName <String>] [-GroupId <String>] -ClearAll [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
OwnerIdentifier (Owner, UPN, Mail, Id, UserId, Name)String[]User principal name, display name, or object ID. Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every OwnerIdentifier as an object ID (skip name lookup).NoFalse
ClearAllSwitchRemove all owners from the group. Prompts for confirmation.NoFalse
PassThruSwitchEmit a status object per owner.NoFalse

*Use either GroupName or GroupId.

Examples

"user1@contoso.com","user2@contoso.com" | Remove-EntraGroupOwner -GroupName "Project Team"
Remove-EntraGroupOwner "Project Team" "user1@contoso.com" -PassThru
Remove-EntraGroupOwner -GroupName "Project Team" -ClearAll
Remove-EntraGroupOwner -GroupName "Project Team" -ClearAll -WhatIf
Owner resolution

Add/Remove-EntraGroupOwner use the same user resolver behavior as the membership cmdlets, and Copy-EntraGroupOwner preserves existing destination owners while skipping duplicates.

Remove-EntraGroupUser​

Remove one or more users from an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

Syntax

Remove-EntraGroupUser [-GroupName <String>] [-GroupId <String>] [[-UserIdentifier] <String[]>] [-TreatInputAsId] [-PassThru]
Remove-EntraGroupUser [-GroupName <String>] [-GroupId <String>] -ClearAll [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (Group, DisplayName)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
UserIdentifier (User, UPN, Mail, Id, UserId)String[]UPN/display name/object ID, external e-mail for invited guests, plus short identifiers (alias/SamAccountName/UPN prefix). Pipeline accepted.Yes-
TreatInputAsIdSwitchTreat every UserIdentifier as an object ID (skip name lookup).NoFalse
ClearAllSwitchRemove all user members from the group (devices and other objects are not removed). Prompts for confirmation.NoFalse
PassThruSwitchEmit a status object per user.NoFalse

*Use either GroupName or GroupId.

Examples

"user1@contoso.com","user2@contoso.com" | Remove-EntraGroupUser -GroupName "Project Team"
Remove-EntraGroupUser "Project Team" "user1@contoso.com" -PassThru
Remove-EntraGroupUser -GroupName "Project Team" -ClearAll
Remove-EntraGroupUser -GroupName "Project Team" -ClearAll -WhatIf
User resolution

Add/Get/Remove-EntraGroupUser accept the external e-mail address of an invited Entra guest. Tenant UPNs and object IDs keep the direct Microsoft Graph lookup (sent in batches of 20 per request); only identities Graph can't find fall back to the shared resolver (Find-UserRecipient) for a Graph-compatible identity.

Search-EntraGroup​

Find Entra groups by display name and/or description (Graph scopes: Group.Read.All, Directory.Read.All).

Syntax

Search-EntraGroup -SearchText <String> [-SearchIn <String>] [-GridView]
ParameterTypeDescriptionRequiredDefault
SearchText (Search, Query, Text, Name, DisplayName, Description)StringText to search in display name and/or description. Pipeline accepted.Yes-
SearchInStringSearch target: DisplayName, Description, Any.NoDisplayName
GridViewSwitchShow details in Out-GridView.NoFalse

Examples

Search-EntraGroup -SearchText "java"
Search-EntraGroup -SearchText "jre"
Search-EntraGroup -SearchText "legacy apps" -SearchIn Description
"marketing" | Search-EntraGroup -SearchIn Any -GridView

Set-EntraGroupDescription​

Update the description of an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

The first positional argument is treated as the group identifier, so you can pass the current group name or its object ID without typing -GroupName or -GroupId.

Syntax

Set-EntraGroupDescription -GroupName <String> -Description <String> [-PassThru]
Set-EntraGroupDescription -GroupId <String> -Description <String> [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (DisplayName, Name)StringTarget group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
DescriptionStringNew description. Pass an empty string to clear it.Yes-
PassThruSwitchReturn the updated group object.NoFalse

*Use either GroupName or GroupId.

Examples

Set-EntraGroupDescription GitLab-Prod -Description "Production GitLab access group"
Set-EntraGroupDescription -GroupName "GitLab-Prod" -Description "Production GitLab access group"
Set-EntraGroupDescription -GroupId "00000000-0000-0000-0000-000000000000" -Description "" -PassThru

Set-EntraGroupDisplayName​

Update the display name of an Entra group (Graph scopes: Group.ReadWrite.All, Directory.Read.All).

The first positional argument is treated as the current group identifier, so you can pass the current group name or its object ID without typing -GroupName or -GroupId.

Syntax

Set-EntraGroupDisplayName -GroupName <String> -DisplayName <String> [-PassThru]
Set-EntraGroupDisplayName -GroupId <String> -DisplayName <String> [-PassThru]
ParameterTypeDescriptionRequiredDefault
GroupName (CurrentName, CurrentDisplayName)StringCurrent group display name.Yes*-
GroupIdStringTarget group object ID (use instead of GroupName).Yes*-
DisplayNameStringNew display name for the group.Yes-
PassThruSwitchReturn the updated group object.NoFalse

*Use either GroupName or GroupId.

Examples

Set-EntraGroupDisplayName GitLab-Prod -DisplayName "GitLab - Production"
Set-EntraGroupDisplayName -GroupName "GitLab-Prod" -DisplayName "GitLab - Production"
Set-EntraGroupDisplayName -GroupId "00000000-0000-0000-0000-000000000000" -DisplayName "GitLab - Production" -PassThru