Created
December 29, 2016 09:28
-
-
Save RichardHan/79ed40a24f8fcc20a83a946ee28cf22a to your computer and use it in GitHub Desktop.
Get DL member via powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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