Running responsive gui with wokflows
Posted: Wed Sep 11, 2019 1:00 pm
Hello Guys,
I have the below code, I'm trying to start multiple Azure Vms using workflow so I can use foreach with parallel property and start all at the same time, I tried to add it to a jobscript, but it only starts the first VM of the txt file, I have added the Params for the workflow, i've tested it printing the data into a textbox and it shows all the VMs listed inside the txt but, inside the jobscrpit it only start the first VM.
It is possible to do this? or I will have to run multiple jobs ? if that the case, can I assign, with a foreach, the vm as the name of the jobs?
Thanks, best regards.
I have the below code, I'm trying to start multiple Azure Vms using workflow so I can use foreach with parallel property and start all at the same time, I tried to add it to a jobscript, but it only starts the first VM of the txt file, I have added the Params for the workflow, i've tested it printing the data into a textbox and it shows all the VMs listed inside the txt but, inside the jobscrpit it only start the first VM.
It is possible to do this? or I will have to run multiple jobs ? if that the case, can I assign, with a foreach, the vm as the name of the jobs?
Code: Select all
$VMs = Get-Content -Path $FileBrowser.FileName
Add-JobTracker `
-Name "StartMultipleVms" `
-ArgumentList $VMs `
-JobScript {
Param ($VMs)
$servers = $Vms
workflow Start-Azure-VM
{
Param ($VMs)
ForEach -parallel ($VM in $VMs)
{
$res = (get-azvm | where { $_.Name -eq $vm }).ResourceGroupName
If ((Get-AzVM -Status -ResourceGroupName $res -Name $vm).Statuses.DisplayStatus[1] -eq "VM Running")
{
Write-Output "`nVM $vm is already online."
}
else
{
$startvm = Start-AzVM -ResourceGroupName $res -Name $VM
Write-Output "VM $VM Was correctly started"
}
}
}
Start-Azure-VM $VMs
} -CompletedScript {
$results = Receive-Job -Name "StartMultipleVms"
$EstadoVM.Text = $results | Out-String
}