Office 365 Groups reporting

Script for listing all groups with owners and members in Office 365.
Added count of groups left to process to see progress when running scripts in large environments.

Run either:

Get-UnifiedGroup | Get-Member
or
Get-UnifiedGroupLinks | Get-Member
to see what other properties you get add to the report.

The script creates one CSV file for information about all members/owners in each group and a CSV file for group names with number of owners, members and external members.

Read more:
Get-UnifiedGroup
Get-UnifiedGroupLinks

#Create $Info array.
$Info = @()

#Create $GroupInfo array.
$GroupInfo = @()

#Collects all groups and specified properties
$Groups = Get-UnifiedGroup | Select-Object Alias,Accesstype,ManagedBy,PrimarySmtpAddress,Displayname,Notes,GroupMemberCount,GroupExternalMemberCount,WhenChanged

#Counts number of groups.
$GroupsCount = ($Groups).count

#Creates a input to $Info for evry owner and member of each group.
#First inputs evry owner of the group, then evry member of the group.
#Creates a input to $GroupInfo for each group.
foreach($Group in $Groups) {

    Write-Host -Object "Number of Groups left to process $GroupsCount" -ForegroundColor Green
    $Members = Get-UnifiedGroupLinks -Identity $Group.alias -LinkType members
    $Owners = Get-UnifiedGroupLinks -Identity $Group.alias -LinkType owners
    $OwnerCount = $Group.ManagedBy

    $Object=[PSCustomObject]@{
        Group = $Group.Displayname
        NumberOfOwners = $OwnerCount.count
        NumberOfMembers = $Group.GroupMemberCount
        NumberOfExternalMembers = $Group.ExternalMemberCount
    }
    $GroupInfo+=$Object

    foreach($Owner in $Owners){
        $Object=[PSCustomObject]@{
            Name = $Group.Displayname
            Group = $Group.Alias
            Email = $Group.PrimarySmtpAddress
            UserName = $Owner.name
            NumberOfMembers = $Group.GroupMemberCount
            MemberOrOwner = 'Owner'
            NumberOfOwners = $OwnerCount.count
            GroupType = $Group.AccessType
            ExternalMemberCount = $Group.GroupExternalMemberCount
            WhenChanged = $Group.WhenChanged
            Description = $Group.Notes
            }#EndPSCustomObject
        $Info+=$object
    }

    foreach($Member in $Members){
        $Object=[PSCustomObject]@{
            Name = $Group.Displayname
            Group = $Group.Alias
            Email = $Group.PrimarySmtpAddress
            UserName = $Member.name
            NumberOfMembers = $Group.GroupMemberCount
            MemberOrOwner = 'Member'
            NumberOfOwners = $OwnerCount.count
            GroupType = $Group.AccessType
            ExternalMemberCount = $Group.GroupExternalMemberCount
            WhenChanged = $Group.WhenChanged
            Description = $Group.Notes
            }#EndPSCustomObject
        $Info+=$object
    }

    $GroupsCount--

}

$Info | Export-Csv c:\script\Info.csv -Encoding utf8 -NoTypeInformation -NoClobber
$GroupInfo | Export-Csv c:\script\GroupInfo.csv -Encoding utf8 -NoTypeInformation -NoClobber

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s