非常に大規模なサーバーで使用するために、次のコードを高速化する方法が必要です。必要なのはフルネーム パラメータのリストだけです。次のようなものを使用したいと思います: http://newsqlblog.com/2012/05/22/concurrency-in-powershell-multi-threading-with-runspaces/
私はそれについて読んでいましたが、それは非常に単純に思えますが、スレッドが既存のプールに新しいスレッドを作成できるようにすること、およびそのプールを渡す方法について頭を悩ませることはできません。
これの速度はひどいものであり、私が利用しているよりもはるかに多くのリソースがあるため、どんな助けも素晴らしいでしょう.
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
}
}
}
注: v2.0 に制限されています
概要: 私は基本的に、$depth までのすべてのフォルダーへのパスを、デジタル的に可能な限り高速に配列に入れる必要があります。
悲惨な失敗の試み:
$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()