-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeOnlineGetOffice365GroupsReports.ps1
More file actions
78 lines (63 loc) · 3.09 KB
/
Copy pathExchangeOnlineGetOffice365GroupsReports.ps1
File metadata and controls
78 lines (63 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
## Exchange Online: PowerShell Script to Get Office 365 Group Information and Membership Details (o365 Groups) ##
## Resource: https://alexholmeset.blog/2017/08/24/office-365-groups-reporting
#Connect to Exchange Online
Import-PSSession $(New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Authentication Basic -AllowRedirection -Credential $(Get-Credential))
#Create $Info Membership array.
$Info = @()
#Create $GroupInfo Summary 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:\temp\o365GroupInfoMembership.csv" -Encoding utf8 -NoTypeInformation -NoClobber #Change this path to match your environment
$GroupInfo | Export-Csv "C:\temp\o365GroupInfoSummary.csv" -Encoding utf8 -NoTypeInformation -NoClobber #Change this path to match your environment