forked from stank58/Powershell-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowershell - List all DL groups and members.ps1
More file actions
31 lines (24 loc) · 1.22 KB
/
Powershell - List all DL groups and members.ps1
File metadata and controls
31 lines (24 loc) · 1.22 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
https://www.morgantechspace.com/2015/06/powershell-export-distribution-list-members-to-csv.html
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
(If Import Session fails run Set-ExecutionPolicy RemoteSigned) and select 'y'
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
If($members) {
$members=$members + ";" + $_.Name
} Else {
$members=$_.Name
}
}
New-Object -TypeName PSObject -Property @{
GroupName = $group
Members = $members
}
} | Export-CSV "C:\Location\Name-of-file.csv" -NoTypeInformation -Encoding UTF8
--------------------------------------------------------------------------------------------
foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | sort displayname | ft @{expression={$_.displayname};Label=”$group”} | Out-File c:\support\DistributionListMembers.csv -append}
Remove-PSSession $Session