-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemoteCall-Deploy.ps1
44 lines (38 loc) · 1.48 KB
/
RemoteCall-Deploy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$executionSteps = @(
@{
"testserver-1" = @{
JobName = "Deploy_Test1";
ScriptName = "Deploy"
};
"testserver-2" = @{
JobName = "Deploy_Test2";
ScriptName = "Deploy"
}
}
)
foreach($step in $executionSteps)
{
$resultJobs = @();
foreach($stepKey in ([HashTable] $step).Keys | Where-Object { ([HashTable] $step[$_]).Count -gt 0 })
{
$scriptName = $step[$stepKey].ScriptName
[ScriptBlock] $transportInvoke = { param([string] $scriptName) ; . ("C:\AuCRM-PSDeployment\{0}.ps1" -f $scriptName) }
$resultJobs += Invoke-Command -ComputerName $stepKey `
-AsJob `
-JobName $step[$stepKey].JobName `
-ScriptBlock $transportInvoke `
-ArgumentList @($scriptName) `
-Authentication Default `
-ErrorAction Stop
# (Get-Job | ? { $_.Name -eq $step[$stepKey].JobName })
}
If($resultJobs.Count -lt 1) { Continue }
# Wait-Job -Job $resultJobs | Out-Null
Write-Host -ForegroundColor Yellow ("Starting executing jobs on: {0}" -f ((([HashTable] $step).Keys) -join ","))
Receive-Job -Job $resultJobs -Wait `
| ForEach-Object { Write-Host -ForegroundColor Cyan "Result of executions: $($_)" }
# Clean-up all
Get-Job `
| Where-Object { $_.Location -in ([HashTable] $step).Keys } `
| ForEach-Object { Remove-Job -Job $_ }
}