第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Powershell可以并行運行命令嗎?

Powershell可以并行運行命令嗎?

Powershell可以并行運行命令嗎?我有一個powershell腳本對一堆圖像進行一些批處理,我想做一些并行處理。Powershell似乎有一些后臺處理選項,如啟動作業(yè),等待作業(yè)等,但我找到的并行工作的唯一好資源是編寫腳本文本并運行它們(PowerShell多線程)理想情況下,我喜歡類似于.net 4中的并行foreach的東西。有點像:foreach-parallel -threads 4 ($file in (Get-ChildItem $dir)){    .. Do Work}也許我會更好的只是下降到c#...
查看完整描述

3 回答

?
炎炎設(shè)計

TA貢獻1808條經(jīng)驗 獲得超4個贊

您可以使用后臺作業(yè)在Powershell 2中執(zhí)行并行作業(yè)。查看Start-Job和其他作業(yè)cmdlet。

# Loop through the server listGet-Content "ServerList.txt" | %{

  # Define what each job does
  $ScriptBlock = {
    param($pipelinePassIn) 
    Test-Path "\\$pipelinePassIn\c`$\Something"
    Start-Sleep 60
  }

  # Execute the jobs in parallel
  Start-Job $ScriptBlock -ArgumentList $_}Get-Job# Wait for it all to completeWhile (Get-Job -State "Running"){
  Start-Sleep 10}# Getting the information back from the jobsGet-Job | Receive-Job


查看完整回答
反對 回復(fù) 2019-08-16
?
LEATH

TA貢獻1936條經(jīng)驗 獲得超7個贊

史蒂夫湯森的回答在理論上是正確的,但在實踐中卻沒有,正如@likwid指出的那樣。我修改后的代碼考慮了工作環(huán)境障礙 -默認情況下沒有任何障礙超越這個障礙!因此,自動$_變量可以在循環(huán)中使用,但不能直接在腳本塊中使用,因為它位于作業(yè)創(chuàng)建的單獨上下文中。

要將變量從父上下文傳遞到子上下文,請使用-ArgumentList參數(shù)on Start-Job發(fā)送它并param在腳本塊內(nèi)部使用它來接收它。

cls# Send in two root directory names, one that exists and one that does not.# Should then get a "True" and a "False" result out the end."temp", "foo" | %{

  $ScriptBlock = {
    # accept the loop variable across the job-context barrier
    param($name) 
    # Show the loop variable has made it through!
    Write-Host "[processing '$name' inside the job]"
    # Execute a command
    Test-Path "\$name"
    # Just wait for a bit...
    Start-Sleep 5
  }

  # Show the loop variable here is correct
  Write-Host "processing $_..."

  # pass the loop variable across the job-context barrier
  Start-Job $ScriptBlock -ArgumentList $_}# Wait for all to completeWhile (Get-Job -State "Running") { Start-Sleep 2 }# Display output from all jobsGet-Job | Receive-Job# CleanupRemove-Job *

(我通常喜歡提供PowerShell文檔的參考作為支持證據(jù),但是,唉,我的搜索沒有結(jié)果。如果您碰巧知道上下文分離的記錄,請在此發(fā)表評論以告訴我!)


查看完整回答
反對 回復(fù) 2019-08-16
  • 3 回答
  • 0 關(guān)注
  • 995 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號