Invoke-Parallel
Invoke-Parallel copied to clipboard
How we can use Invoke-Parallel to fetch ADUser data?
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
}
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 :)
If you just want to get the
SamAccountName
andMemberOf
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.
Oh I see. Can you share your example code you have so far? If not, can you share your pseudo-code?
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