Skip to content

Instantly share code, notes, and snippets.

@RichardHan
Created December 29, 2016 09:28
Show Gist options
  • Save RichardHan/79ed40a24f8fcc20a83a946ee28cf22a to your computer and use it in GitHub Desktop.
Save RichardHan/79ed40a24f8fcc20a83a946ee28cf22a to your computer and use it in GitHub Desktop.
Get DL member via powershell
Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell
$DLName = "DL_Name"
$ADServer = "AD_Server_Name"
$ResultList = @()
$Groups = Get-ADGroup -Properties * -Filter{name -like $DLName} -Server $ADServer |Select Name, ManagedBy|
Foreach-Object{
$Group = $_
$ManagedBy = $Group.ManagedBy -replace '^CN=|,.*$'
$User = get-adgroupmember $Group.Name -Server $ADServer |Foreach-Object{
$ResultList+=New-Object -TypeName PSObject -Property @{
UserName= $_.Name
GroupName = $Group.Name
ManagedBy = $ManagedBy
}
}
}
Write-Output $ResultList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment