我正在编写一个脚本,将500多条DNS记录迁移到Windows 2008(从'03开始),然后通过DNSCMD(内置MS DNS工具)操纵属性。
无论如何 - 在DNS中有一个限制,如果你做“太快”的事情,它会开始窒息 - 我以前在我的旧DOS脚本中看到过这种情况。
那就是说,我如何批处一个foreach循环?
比如(例如用外行人的话来说脚本)
$records = C:\myfile.txt foreach ($record in records) { MyFunction (only to the first 20 records) start-sleep 2 MyFunction (to the next 20 records) ... etc .... }那可能吗? 如果是这样你会如何接近它? 我想我可以在MyFunction之后添加一个简单的start-sleep 1 ,但是有500多条记录,很多功能,这将花费很长时间。 :(我认为在DOS世界中找到的效率方面是最好的。感谢!
I'm writing a script to migrate 500+ DNS records to Windows 2008 (from '03) and then manipulating attributes - all via DNSCMD (builtin MS DNS tool).
Anyways - there is a limitation in DNS where if you do things "too fast" it starts choking on itself - I've seen this before in my old DOS scripts.
That said, how would I batch up a foreach loop?
Like for example (in laymans terms w/ scripting)
$records = C:\myfile.txt foreach ($record in records) { MyFunction (only to the first 20 records) start-sleep 2 MyFunction (to the next 20 records) ... etc .... }Is that possible? If so how would you approach it? I guess I could add a simple start-sleep 1 after MyFunction, but with 500+ records, times many functions, that's gonna take a VERY long time. :( I think batching them is the best in terms of efficiency we've found from the DOS world. Thanks!
最满意答案
如果您从文件中读取它们,可以使用-ReadCount批量处理它们:
Get-Content C:\myfile.txt -ReadCount 20 | foreach { foreach ($record in $_) { MyFunction $record } start-sleep 2 }If you're reading them from a file, you can batch them up using -ReadCount:
Get-Content C:\myfile.txt -ReadCount 20 | foreach { foreach ($record in $_) { MyFunction $record } start-sleep 2 }更多推荐
发布评论