Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Last active December 21, 2022 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrownnycnyc/97c6e15a9540fd6e64217956c71bb26b to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/97c6e15a9540fd6e64217956c71bb26b to your computer and use it in GitHub Desktop.
Thread safe disctionary and using -parallel switch with foreach in powershell
# 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