Created
May 20, 2015 11:22
-
-
Save alexinnes/13ec880bd108449e3bf4 to your computer and use it in GitHub Desktop.
Function to get all users from a specified group.
This file contains 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
<# | |
.Synopsis | |
Gets all users associated within a AD Group | |
.DESCRIPTION | |
Gets all users associated within a AD Group | |
.EXAMPLE | |
get-ADUserfromGroup [adgroupname] | |
.EXAMPLE | |
Another example of how to use this cmdlet | |
#> | |
function Get-ADUsersfromGroup | |
{ | |
[CmdletBinding()] | |
[OutputType([int])] | |
Param | |
( | |
# This needs to be a valid AD group | |
[Parameter(Mandatory=$true, | |
ValueFromPipelineByPropertyName=$true, | |
Position=0)] | |
$Param1 | |
) | |
Begin | |
{ | |
$array = @(Get-ADGroupMember $Param1 -Recursive | select -Property samaccountname) | |
} | |
Process | |
{ | |
$table = foreach($element in $array){get-aduser $element.samaccountname -Properties givenname,sn | select -Property givenname,sn} | |
} | |
End | |
{ | |
$table | ft -AutoSize | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment