Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Search through group members one at a time?

$
0
0

I currently have a script that searches through group memberships using "get-adgroupmember" to see if a group contains a user object, and if so, the script performs an action. However, "get-adgroupmember" has to resolve the entire group membership before my script can search through the members to see if any of the members are user objects. What I would like is to be able to search the members one at a time, instead of having to resolve the entire membership before searching through it. That way, as soon as my script encountered a user object as a member, it could perform its action immediately.

Is there a way to search group members one at a time, instead of having to resolve the entire group membership before searching through them?

For example, the following script would take forever on a large domain:

$member = get-adgroup -filter 'name -eq "Domain Users"'| get-adgroupmember | %{$_.objectclass}
If($member = "user"){"User present"}
I would like to have it where as soon as the above script detected a user object, it could take an action and quit, instead of having to resolve every object inside "Domain Users" first.

Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images