In Microsoft 365, groups often have designated owners responsible for managing memberships and permissions. The Get-MgGroupOwner
cmdlet retrieves group owners, but by default, it only provides their IDs. To fetch additional details such as Display Name, User Principal Name (UPN), and Email, you need to pair it with the Get-MgUser
cmdlet. This article highlights the importance of this pairing and demonstrates how to fetch detailed information about group owners.
The following script retrieves the group owners of a specified group and uses Get-MgUser to fetch their personal details:
# Retrieve the detailed information of group owners
$owners = Get-MgGroupOwner -GroupId '7bf57d88-42e1-4c8b-8a44-5a6f04a29073'
foreach ($owner in $owners) {
Get-MgUser -UserId $owner.Id | Select-Object DisplayName, Mail, UserPrincipalName
}
Get-MgGroupOwner
cmdlet fetches the owners of a specific group using the group’s ID.Get-MgUser
cmdlet retrieves additional details for each owner by using their IDs.foreach
loop ensures details are retrieved for each owner individually.$results = foreach ($owner in $owners) {
Get-MgUser -UserId $owner.Id | Select-Object DisplayName, Mail, UserPrincipalName
}
$results | Export-Csv -Path "GroupOwnersDetails.csv" -NoTypeInformation
Error | Cause | Solution |
The specified object was not found in the directory. | The group ID is invalid or does not exist. | Verify the group ID using the Get-MgGroup cmdlet:
|
Insufficient privileges to complete the operation. | Missing permissions like Group.Read.All or User.Read.All . |
Grant the necessary permissions in Azure AD. |
Cannot process a null value. | A group owner might have been removed but still exists as an entry. | Add error handling to skip such cases:
|
Pairing Get-MgGroupOwner
with Get-MgUser
is essential for retrieving detailed information about group owners in Microsoft 365. While Get-MgGroupOwner
provides only the User ID by default, the Get-MgUser
cmdlet allows you to fetch properties like Display Name, Email, and UPN. This pairing is invaluable for managing groups effectively, generating detailed reports, and ensuring compliance. Start using this approach today to streamline your administrative workflows.
© m365corner.com. All Rights Reserved. Design by HTML Codex