如何启动job foreach ip和coostiate ip for文件名称
我有一个脚本来自在这里这是工作:
function CaptureWeight {
Start-Job -Name WeightLog -ScriptBlock {
filter timestamp {
$sw.WriteLine("$(Get-Date -Format MM/dd/yyyy_HH:mm:ss) $_")
}
try {
$sw = [System.IO.StreamWriter]::new("$using:LogDir\$FileName$(Get-Date -f MM-dd-yyyy).txt")
& "$using:PlinkDir\plink.exe" -telnet $using:SerialIP -P $using:SerialPort | TimeStamp
}
finally {
$sw.ForEach('Flush')
$sw.ForEach('Dispose')
}
}
}
i' D希望让他违反IP地址列表,同时还具有与IP关联的名称来设置每个文件的文件名。我在想 $ name = myFilename
和 $ name.ip = 1.1.1.1
以及使用$ filename和$ serialip的东西,但尚未能够让任何接近工作或找到足够接近我想要的示例的示例。
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您可以用 hash表 AS theo 在他的帮助评论中提到。请注意,没有阈值/therottlelimit参数与
start-threadjob
或 由于作业在不同的过程中运行,因为您已经评论了/ runspaces ,没有内置的方式来控制多少个工作可以在同时。如果您愿意控制这个,则需要自己编码。哈希表的另一种替代方法可能是使用CSV(要么来自
import-csv
或用conversfrom-csv
)。Here is one way you could do it with a hash table as Theo mentioned in his helpful comment. Be aware that Jobs don't have a Threshold / ThrottleLimit parameter as opposed to
Start-ThreadJob
orForEach-Object -Parallel
since jobs run in a different process as you have already commented instead of instances / runspaces, there is no built-in way to control how many Jobs can run at the same time. If you wish have control over this you would need to code it yourself.The other alternative to the hash table could be to use a Csv (either from a file with
Import-Csv
or hardcoded withConvertFrom-Csv
).在此处添加我以前答案的另一种选择,使用
runspacepool
实例具有内置的一种并发和重新启动的方式。Adding here another alternative to my previous answer, using a
RunspacePool
instance which has built-in a way of concurrency and enqueuing.