Runspaces - specifically, you can use invoke-parallel (https://github.com/RamblingCookieMonster/Invoke-Parallel). I use it all the time for multi-threading.
Something to keep in mind - += is ok for small datasets, but is pretty evil on very large datasets. Basically, when you do a +=, it doesn't just add to the array, it deletes the array and recreates it with the new member. Probably doesn't matter for an ACL list on a file, but if you are working with hundreds of thousands of items, it can hurt performance pretty bad. From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Todd, Jason Sent: Tuesday, August 02, 2016 4:33 AM To: powershell@lists.myitforum.com Subject: [EXTERNAL] [powershell] Make GET-ACL quicker? Hello All, I'm hoping someone can help me out with making GET-ACL quicker? Scenario: I need to use Get-Acl on over 1million files and folders in a directory root, and then filter on just the ones which have Inheritance set to $false. This is my current code (which take days to run!): ## Loop each file and folder in RootPath Foreach ($Item in $FilesAndFolders){ TRY{ Write-Verbose -message "[TRY] Getting ACLs for: $item" -verbose $ACLs = get-acl $Item.fullname | ForEach-Object {$_.Access} Foreach ($ACL in $ACLs){ $ObjectOut = New-Object -TypeName PsObject $ObjectOut | Add-Member -MemberType NoteProperty -Name "Path" -Value $Item.FullName.ToString() $ObjectOut | Add-Member -MemberType NoteProperty -Name "IdentityReference" -Value $ACL.IdentityReference.ToString() $ObjectOut | Add-Member -MemberType NoteProperty -Name "AccessControlType" -Value $ACL.AccessControlType.ToString() $ObjectOut | Add-Member -MemberType NoteProperty -Name "InheritanceFlags" -Value $ACL.InheritanceFlags $ObjectOut | Add-Member -MemberType NoteProperty -Name "PropagationFlags" -Value $ACL.PropagationFlags $ObjectOut | Add-Member -MemberType NoteProperty -Name "FileSystemRights" -Value $ACL.FileSystemRights.ToString() $ObjectOut | Add-Member -MemberType NoteProperty -Name "IsInherited" -Value $ACL.IsInherited $ACLList += $ObjectOut } } CATCH{ Write-Warning "[CATCH] ERROR getting ACL for $($item.fullname)" -Verbose $ACLErrorsLog += "ERROR getting ACL for $($item.fullname)" } Does anyone know a way to speed up the getting of ACL's, maybe by filtering out the non-inherited objects ? Any help much appreciated! Thank you, Jason This email, the information therein and any attached materials (collectively the "Email") are intended only for the addressee(s) and may contain confidential, proprietary, copyrighted and/or privileged material. If you have received this Email in error please delete it and notify the sender immediately. This Email remains the property of Brevan Howard, which reserves the right to require its return (together with any copies or extracts thereof) at any time upon request. Any unauthorised review, retransmission, dissemination, forwarding, printing, copying or other use of this Email is prohibited. Brevan Howard may be legally required to review and retain outgoing and incoming email and produce it to regulatory authorities and others with legal rights to the information. Internet communications cannot be guaranteed to be secure or error free as information could be intercepted, changed corrupted, lost, arrive late or contain viruses. Brevan Howard accepts no liability for any errors or omissions in this Email which arise as a result of internet transmission. This Email is not an official confirmation of any transaction. Any comments or statements made herein do not necessarily reflect the views of Brevan Howard. This Email is not an offer to sell or solicitation of an offer to buy any security or investment. It does not constitute or contain any investment advice and is being made without regard to the recipients investment objectives, financial situation or means. Past Performance is not an indicator of future results and Brevan Howard provides no assurance that future results will be consistent with any information provided herein or attached hereto. Brevan Howard and the sender make no warranties regarding the accuracy or completeness of the information in this Email and it should not be relied upon and is subject to change without notice. Brevan Howard and its representatives, officers and employees accept no responsibility for any losses suffered as a result of reliance on the information in this Email or the reliability, accuracy, or completeness thereof. In this Email, "Brevan Howard" means Brevan Howard Asset Management LLP ("BHAM"), Brevan Howard Inc., Brevan Howard (Israel) Ltd and their respective affiliates. BHAM is a limited liability partnership authorised and regulated by the Financial Conduct Authority of the United Kingdom and registered in England & Wales (reg. no. OC302636). Nothing in this message is intended to constitute an electronic signature unless a specific statement to the contrary is included in this message. Confidentiality Note: This message is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, transmission, dissemination or other use, or taking of any action in reliance upon this message by persons or entities other than the intended recipient is prohibited and may be unlawful. If you received this message in error, please contact the sender and delete it from your computer.