Export microsoft 365 groups with owner, creation date, and last used if possible.

Good, Anthony 20 Reputation points
2023-09-29T17:47:50.9533333+00:00

i was trying to use get-azureaduser but it doesnt look like its a property in that commandlet.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2023-10-01T00:07:43.6933333+00:00

    @Good, Anthony , use or edit the following PowerShell script to export group owners. You will need MSAL.PS and Microsoft Graph PowerShell SDK installed. There's no "last used" property. For a list of available properties take a look to the documention for user and group resources.

    Connect-MgGraph -AccessToken `
    (    (Get-MsalToken -ClientId 14d82eec-204b-4c2f-b7e8-296a70dab67e -TenantId "string(optional)" `
                -Scopes  "Directory.Read.All", "AuditLog.Read.All" -ForceRefresh).AccessToken |
        ConvertTo-SecureString -AsPlainText -Force)
        
    Get-MgGroup -Property   "id,displayName,createdDateTime"  -ExpandProperty 'owners($select=id,displayName,createdDateTime)' |
    ForEach-Object { $group = $_; $_.Owners | 
        Select-Object  @{N = "GroupId"; E = { $group.id } } , @{N = "GroupDisplayName"; E = { $group.displayName } }, `
        @{N = "GroupCreatedDateTime"; E = { $group.createdDateTime } } , @{N = "OwnerId"; E = { $_.Id } } , `
        @{ N = "OwnerDisplayName"; E = { $_.AdditionalProperties.displayName } } , `
        @{N = "OwnerCreatedDateTime"; E = { $_.AdditionalProperties.createdDateTime } } } |
    ConvertTo-Csv -NoTypeInformation | 
    Out-File GroupOwners.csv -Encoding utf8
    

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.