I am definitely not a PS expert, and I'm not sure this is the best solution 
given what you are attempting. However, I agree with Donnie's note on 
performance with the destruction/creation of arrays as you iterate through. 
Instead you could look at using Array List to store all your information. I had 
a scenario with querying DNS against some databases (300,000+ entries). When I 
used a standard array and += it took nearly 27hrs to run. With the Array List 
it took less than 10mins.

$ACLList = New-Object System.Collections.ArrayList

...

[Void]$ArrayList.Add($ObjectOut)

[Void] just stops output being written to the console, you can remove it, but 
it doesn't really gain you any benefit (other than providing a counter on how 
many objects have been added to the Array List. There may be some massaging to 
get the data how you want, but you may see some significant reductions in 
runtime. I first saw Array List mentioned here and have used it on more than a 
few occasions since:

https://foxdeploy.com/2016/03/23/coding-for-speed/


From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Donnie Taylor
Sent: Tuesday, August 02, 2016 6:58 AM
To: powershell@lists.myitforum.com
Subject: RE: [powershell] Make GET-ACL quicker?


ATTENTION: This email came from an external source. DO NOT open attachments or 
click on links from unknown senders or unexpected emails.

Runspaces - specifically, you can use invoke-parallel 
(https://github.com/RamblingCookieMonster/Invoke-Parallel<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_RamblingCookieMonster_Invoke-2DParallel&d=CwMFAg&c=GtV7VYka8XzFJya76SH24R7OU_QKFTyBlklHoDMCjFY&r=WF1NZuUqAd1bRIxLFT_0wz8npqTRKjPr3_qzGO_dTx_Q3Taym2JWM42n-cKyG-6W&m=h1i02qmQ70WAfRzSB3UY-YcP14jEo0UKqGSmbT6p9l0&s=RRmZW_D6CIfuocodaE5Z0O0pRtsAqZ3h3_qVfa1pFbI&e=>).
  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> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Todd, Jason
Sent: Tuesday, August 02, 2016 4:33 AM
To: powershell@lists.myitforum.com<mailto: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.
Confidentiality Notice: This is a transmission from Community Hospital of the 
Monterey Peninsula. This message and any attached documents may be confidential 
and contain information protected by state and federal medical privacy 
statutes. They are intended only for the use of the addressee. If you are not 
the intended recipient, any disclosure, copying, or distribution of this 
information is strictly prohibited. If you received this transmission in error, 
please accept our apologies and notify the sender. Thank you.



Reply via email to