不允许PowerShell拆分作业空管道元素
我真的很想使用函数不允许PowerShell拆分作业空管道元素,powershell,pipeline,Powershell,Pipeline,我真的很想使用函数splitjob来限制或并行运行同一个脚本块,这样会更快。当我需要在不同的输入上多次启动同一复制命令时,这尤其有用 可以找到该代码,并始终显示以下错误: An empty pipe element is not allowed. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : EmptyPipeE
splitjob
来限制或并行运行同一个脚本块,这样会更快。当我需要在不同的输入上多次启动同一复制命令时,这尤其有用
可以找到该代码,并始终显示以下错误:
An empty pipe element is not allowed.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : EmptyPipeElement
我知道问题在这个函数中,但我似乎无法解决它:
function Init ($InputQueue){
# Create the shared thread-safe queue and fill it with the input objects
$Queue = [Collections.Queue]::Synchronized([Collections.Queue]@($InputQueue))
$QueueLength = $Queue.Count
# Do not create more runspaces than input objects
if ($MaxPipelines -gt $QueueLength) {$MaxPipelines = $QueueLength}
# Create the script to be run by each runspace
$Script = "Set-Location '$PWD'; "
$Script += {
$SplitJobQueue = $($Input)
& {
trap {continue}
while ($SplitJobQueue.Count) {$SplitJobQueue.Dequeue()}
} |
}.ToString() + $Scriptblock
# Create an array to keep track of the set of pipelines
$Pipelines = New-Object System.Collections.ArrayList
# Collect the functions and aliases to import
$ImportItems = ($Function -replace '^','Function:') +
($Alias -replace '^','Alias:') |
Get-Item | select PSPath, Definition
$stopwatch = New-Object System.Diagnostics.Stopwatch
$stopwatch.Start()
}
谢谢你的帮助。因为这个小函数如果能正常工作,可能会对我有很大帮助。在本节中:
$Script += {
$SplitJobQueue = $($Input)
& {
trap {continue}
while ($SplitJobQueue.Count) {$SplitJobQueue.Dequeue()}
} |
}.ToString() + $Scriptblock
该管道似乎没有任何理由存在。没错,但当我将其从函数中删除时,它根本不起作用。问题中似乎没有足够的信息来确定如果删除该管道,它为什么不起作用。我只能告诉你为什么会出现这个错误,以及如何修复它。我放弃了这个,同时我创建了我自己的工作节流功能,因为这个太复杂了。无论如何谢谢你的持续支持,我真的很感激。