Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell GCI, to Depth speed
    primarykey
    data
    text
    <p>I need a way to speed up the following code for use on a VERY large server. All I need is the list of the fullname param. I would like to use something like the following: <a href="http://newsqlblog.com/2012/05/22/concurrency-in-powershell-multi-threading-with-runspaces/" rel="nofollow">http://newsqlblog.com/2012/05/22/concurrency-in-powershell-multi-threading-with-runspaces/</a></p> <p>I was reading about it and it seems pretty simple, however I cannot wrap my head around allowing threads to create new Threads in the existing pool... and how to pass that pool along.</p> <p>Any help would be great, because the speed of this is just terrible and I have SOOOO many more resources then I am utalizing.</p> <pre><code>Function Get-ChildItemToDepth { Param( [String]$Path = $PWD, [int]$ToDepth = 255, [Byte]$CurrentDepth = 0 ) if ($ToDepth -lt 0) { return get-item $path } $CurrentDepth++ Get-ChildItem $Path | Where-Object { $_.PSIsContainer } | %{ $_ If ($CurrentDepth -le $ToDepth) { Get-ChildItemToDepth -Path $_.FullName ` -ToDepth $ToDepth -CurrentDepth $CurrentDepth } } } </code></pre> <p>NOTE: I am restricted to v2.0</p> <p>Summary: I basically need the path to all folders up to $depth into an array as fast as digitally possible.</p> <p>MISSERABLE FAILURE ATTEMPT:</p> <pre><code>$func = ` { Param( [String]$Path = $PWD, [int]$ToDepth = 255, [Byte]$CurrentDepth = 0, $p = $pool ) if ($ToDepth -lt 0) { return $path } $CurrentDepth++ $folders = Get-ChildItem $Path | Where-Object { $_.PSIsContainer } | select -expand FullName If ($CurrentDepth -le $ToDepth) { foreach ($path in $folders) { $pipeline = [System.Management.Automation.PowerShell]::create() $pipeline.RunspacePool = $pool $pipeline.AddScript($func).AddArgument($path).AddArgument($ToDepth).AddArgument($CurrentDepth).AddArgument($pool) $AsyncHandle = $pipeline.BeginInvoke() $folders += $pipeline.EndInvoke($AsyncHandle) $pipeline.Dispose() } } return $folders } $path = "\\server\users-folder\" $toDepth = 3 $pool = [RunspaceFactory]::CreateRunspacePool(1, 4) $pool.ApartmentState = "STA" $pool.Open() $pipeline = [System.Management.Automation.PowerShell]::create() $pipeline.RunspacePool = $pool $pipeline.AddScript($func).AddArgument($path).AddArgument($toDepth).AddArgument($CurrentDepth).AddArgument($pool) $AsyncHandle = $pipeline.BeginInvoke() $RESULTS = $pipeline.EndInvoke($AsyncHandle) $pipeline.Dispose() $pool.Close() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload