Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amolsp777 opened this issue Oct 4, 2018 · 4 comments
Open

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

amolsp777 opened this issue Oct 4, 2018 · 4 comments

Comments

@amolsp777
Copy link

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

}

@adamrushuk
Copy link

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 :)

@amolsp777
Copy link
Author

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.

@adamrushuk
Copy link

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

@amolsp777
Copy link
Author

amolsp777 commented Oct 4, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants