Last active
December 21, 2022 14:17
-
-
Save mbrownnycnyc/97c6e15a9540fd6e64217956c71bb26b to your computer and use it in GitHub Desktop.
Thread safe disctionary and using -parallel switch with foreach in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# summary of code covered here: https://isc.sans.edu/diary/Port%20Scanning%20in%20Powershell%20Redux%3A%20Speeding%20Up%20the%20Results%20%28challenge%20accepted!%29/29324 | |
$gkeclusters = [System.Collections.Concurrent.ConcurrentDictionary[string,object]]::new() | |
$gcpprojects.projectId | % -ThrottleLimit 10 -Parallel { | |
write-host "checking $($_)" | |
$dict = $using:gkeclusters | |
$dict.TryAdd($(gcloud container clusters list --project $_ --format json), $_) | out-null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment