Invoke-Parallel icon indicating copy to clipboard operation
Invoke-Parallel copied to clipboard

How we can use Invoke-Parallel to fetch ADUser data?

Open amolsp777 opened this issue 6 years ago • 4 comments

I want to get all the users from AD and foreach user I want to fetch multiple properties parallel. Because ForEach process is taking time to get the details.

sample dummy code. $users = Get-ADUser -Filter *

ForEach($user in $users){

$SamName = $user.samaccountname

$memberof = $user.memberof

}

amolsp777 avatar Oct 04 '18 19:10 amolsp777

If you just want to get the SamAccountName and MemberOf user properties, this should work for you:

$additionalUserProperties = 'MemberOf'  
$adUsers = Get-ADUser -Filter * -Properties $additionalUserProperties
$adUsers | Select-Object -Property 'SamAccountName', $additionalUserProperties

The MemberOf property is not returned by default, so you will have to request additional properties, eg: $additionalUserProperties = 'MemberOf', 'OtherProperty1', 'OtherProperty2'

Hope that helps :)

adamrushuk avatar Oct 04 '18 20:10 adamrushuk

If you just want to get the SamAccountName and MemberOf user properties, this should work for you:

$additionalUserProperties = 'MemberOf'  
$adUsers = Get-ADUser -Filter * -Properties $additionalUserProperties
$adUsers | Select-Object -Property 'SamAccountName', $additionalUserProperties

The MemberOf property is not returned by default, so you will have to request additional properties, eg: $additionalUserProperties = 'MemberOf', 'OtherProperty1', 'OtherProperty2'

Hope that helps :)

Thanks for the update but I was looking to run this in parallel if I want to try for Get-adgroup and get the associated member's details so foreach takes time to calculate so want to check if I can run this to get information for each group parallelly.

amolsp777 avatar Oct 04 '18 20:10 amolsp777

Oh I see. Can you share your example code you have so far? If not, can you share your pseudo-code?

adamrushuk avatar Oct 04 '18 21:10 adamrushuk

Somehow i figured it out but i used maxqueue as 1, because if I put more then 1 it is not fetching detailed information for some groups (not complete within that time). Not sure if I am using the correct combination of Invoke-Parallel syntaxes.

By using maxqueue value 1, it is also almost slow, but getting accurate data.

Adding my code, how I figured it out and how I am using it, but might be there is better way to use this so need experts advise :)

attaching file. GroupMembersCheck_ps1.txt

amolsp777 avatar Oct 04 '18 21:10 amolsp777