并行化powershell脚本执行

Sam*_*abu 1 parallel-processing powershell powerpoint dependencies

我有8个powershell脚本.他们中很少有依赖.这意味着它们不能并行执行.它们应该一个接一个地执行.

一些Powershell脚本没有依赖性,它可以并行执行.

以下是详细解释的依赖关系

    Powershell scripts 1, 2, and 3 depend on nothing else
    Powershell script 4 depends on Powershell script 1
    Powershell script 5 depends on Powershell scripts 1, 2, and 3
    Powershell script 6 depends on Powershell scripts 3 and 4
    Powershell script 7 depends on Powershell scripts 5 and 6
    Powershell script 8 depends on Powershell script 5
Run Code Online (Sandbox Code Playgroud)

我知道通过手动硬编码可以实现依赖性.但是可以添加10个powershell脚本,并且可以添加它们之间的依赖性.

通过寻找依赖性,有没有人实现并行性?如果是这样,请分享我如何进行.

rav*_*nth 5

您需要查看PowerShell 3.0工作流程.它提供您所需的功能.像这样的东西:

workflow Install-myApp {
    param ([string[]]$computername)
    foreach -parallel($computer in $computername) {
        "Installing MyApp on $computer"
        #Code for invoking installer here
        #This can take as long as 30mins and may reboot a couple of times
    }
}

workflow Install-MyApp2{
    param ([string[]]$computername)
    foreach -parallel($computer in $computername) {
        "Installing MyApp2 on $computer"
        #Code for invoking installer here
        #This can take as long as 30mins!
    }
}

WorkFlow New-SPFarm {
    Sequence {
        Parallel {
            Install-MyApp2 -computername "Server2","Server3"
            Install-MyApp -computername "Server1","Server4","Server5"
        }
        Sequence {
            #This activity can happen only after the set of activities in the above parallel block are complete"
            "Configuring First Server in the Farm [Server1]"

            #The following foreach should take place only after the above activity is complete and that is why we have it in a sequence
            foreach -parallel($computer in $computername) {
                "Configuring SharePoint on $computer"
            }
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)