-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho365_groupmembers.ps1
24 lines (18 loc) · 1.08 KB
/
o365_groupmembers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$OutputFile = Read-Host -Prompt "Enter the path and file name for the .csv file eg. C:\users\admin\desktop\filename.csv"
Out-File -FilePath $OutputFile -InputObject "Group DisplayName, Group Type, Group Email, Member DisplayName, Member Email" -Encoding UTF8
$objGroups = Get-msolgroup -All | Sort-object objectid
Foreach ($objGroup in $objGroups)
{
write-host "Processing $($objGroup.DisplayName)..."
$objGMembers = Get-MsolGroupMember -groupobjectid $($objGroup.objectid)
write-host "Found $($objGMembers.Count) members..."
$name = $_.objectid
$grouptype = $_.grouptype
$displayname = $_.displayname
$email = $_.proxyaddresses
Foreach ($objMember in $objGMembers)
{
Out-File -FilePath $OutputFile -InputObject "$($objGroup.DisplayName),$($objGroup.GroupType),$($objGroup.proxyaddresses),$($objMember.DisplayName),$($objMember.EmailAddress)" -Encoding UTF8 -append
write-host "`t$($objGroup.DisplayName),$($objGroup.GroupType),$($objGroup.proxyaddresses),$($objMember.DisplayName),$($objMember.EmailAddress)"
}
}