Skip to content

Instantly share code, notes, and snippets.

@alexinnes
Created May 20, 2015 11:22
Show Gist options
  • Save alexinnes/13ec880bd108449e3bf4 to your computer and use it in GitHub Desktop.
Save alexinnes/13ec880bd108449e3bf4 to your computer and use it in GitHub Desktop.
Function to get all users from a specified group.
<#
.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