function get-recursegroupmembers{ [CmdletBinding()] param ( [Parameter(mandatory=$true,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)] [string]$groupname ) $users = @() $groups = get-adgroupmember $groupname foreach($object in $groups){ if ($object.objectclass -eq "group"){ get-recursegroupmembers $object } if ($object.objectclass -eq "user"){ $users += $object } } $users } |
When I realised that this would do just fine;
get-adgroupmember $group -Recursive
|
So yeah, lesson for the day is don't spend valuable time writing stuff when the problem has already been solved.
I always stress reading and re-reading help and examples. Even I will re-read help and discover something I didn't know about or pay attention to before.
ReplyDelete