AutomatedLab / AutomatedLab/AutomatedLab
Invoke-LabCommand -PostInstallationActivity -AsJob not creating a background job
- Dominant language
- PowerShell
- Stars
- 2.2k
- Forks
- 384
- PR merge metrics
- No merged PRs in 30d
Description
I've created custom Citrix roles to be installed on a series of VM's. These need to be installed in a sequence which AutomatedLab seems to do via the order the custom roles are added to the LabMachineDefinition. But they have no other dependency so executing them in parallel across multiple machines would save lots of time.
In order to execute in parallel I'm using the following command:
`$PostInstalljobs = Invoke-LabCommand -PostInstallationActivity -ActivityName 'Post-installation' -ComputerName $postInstallMachines -AsJob`
This is not creating a job per-machine and executing in the background, it is executing sequentially starting for the first machine and first role, waiting for that first role execution to finish, then executing the next role.. Once all roles are complete for the first machine it moves onto the next machine.
## Expected behavior
Each machine should have a job created to be executed in the background and the roles installed in order
## Actual behavior
AsJob appears to be ignored and each machine is operated on one at a time.
```output
VERBOSE: [10:56:06][Write-LogFunctionEntry] Invoke-LabCommand Entering...
(PostInstallationActivity=True,ActivityName=Post-installation,ComputerName=CTX01,AsJob=True,NoDisplay=True,PassThru=True,Verbose=True)
VERBOSE: [10:56:06][Invoke-LabCommand] Executing lab command activity 'Post-installation' on machines 'CTX01'
VERBOSE: [10:56:06][Write-LogFunctionEntry] Get-LabVM Entering... (IncludeLinux=True)
VERBOSE: [10:56:06][Write-LogFunctionEntry] Get-LabVM Entering... (ComputerName=CTX01)
VERBOSE: [10:56:06][Write-LogFunctionEntry] Get-LabVM Entering... (ComputerName=CTX01,IncludeLinux=True)
VERBOSE: [10:56:07][Write-LogFunctionExit] Get-LabVMStatus...leaving...(Time elapsed: 00:00:00:031)
VERBOSE: [10:56:07][Write-ScreenInfo] Performing pre/post-installation tasks defined for each machine
VERBOSE: [10:56:07][Write-ScreenInfo] 10:56:07|08:27:38|00:00:00.000| - Performing pre/post-installation tasks defined for each machine
10:56:07|08:27:38|00:00:00.000| - Performing pre/post-installation tasks defined for each machine
VERBOSE: [10:56:07][Write-ScreenInfo] Installing Custom Role 'CitrixLicensing' on machine 'CTX01'
VERBOSE: [10:56:07][Write-ScreenInfo] 10:56:07|08:27:38|00:00:00.000| - Installing Custom Role 'CitrixLicensing' on machine 'CTX01'
10:56:07|08:27:38|00:00:00.000| - Installing Custom Role 'CitrixLicensing' on machine 'CTX01'
10:56:07|08:27:38|00:00:00.000| - Validating lab definition
10:56:10|08:27:41|00:00:03.406| - Success
10:56:10|08:27:41|00:00:03.500| - Lab 'TestEnv' hosted on 'HyperV' imported with 6 machines
VERBOSE: [10:56:10][Write-LogFunctionEntry] Get-LabVM Entering... (ComputerName=CTX01)
VERBOSE: [10:56:10][Write-ScreenInfo] Detected the following operating system for 'CTX01' : Windows Server 2022 Standard (Desktop Experience)
VERBOSE: [10:56:10][Write-ScreenInfo] 10:56:10|08:27:41|00:00:03.593| - Detected the following operating system for 'CTX01' : Windows Server 2022 Standard
(Desktop Experience)
10:56:10|08:27:41|00:00:03.593| - Detected the following operating system for 'CTX01' : Windows Server 2022 Standard (Desktop Experience)
VERBOSE: [10:56:10][Write-ScreenInfo] Found Citrix product: Citrix_Virtual_Apps_and_Desktops version: 7.2109
VERBOSE: [10:56:10][Write-ScreenInfo] 10:56:10|08:27:41|00:00:03.609| - Found Citrix product: Citrix_Virtual_Apps_and_Desktops version: 7.2109
10:56:10|08:27:41|00:00:03.609| - Found Citrix product: Citrix_Virtual_Apps_and_Desktops version: 7.2109
VERBOSE: [10:56:10][Write-ScreenInfo] Selected version of Citrix Licensing (7.2109) supports this operating system 2022
VERBOSE: [10:56:10][Write-ScreenInfo] 10:56:10|08:27:41|00:00:03.640| - Selected version of Citrix Licensing (7.2109) supports this operating system 2022
10:56:10|08:27:41|00:00:03.640| - Selected version of Citrix Licensing (7.2109) supports this operating system 2022
...
```
## Steps to reproduce
Create custom roles that take a while (eg, HostStart.ps1 with a Start-Sleep 600)
Add Custom Role to multiple LabMachineDefinition
Create Machines in Lab:
```powershell
Install-Lab -BaseImages -NetworkSwitches -VMs -Domains
```
Attempt to execute post installation activities manually:
```powershell
$PostInstallActivityMachines = Get-LabMachineDefinition | Where {$_.PostInstallationactivity.count -ge 1}
$postInstallJobs = New-Object System.Collections.Generic.List[PsObject]
foreach ($PostInstallMachine in $PostInstallActivityMachines) {
$PostInstalljob = Invoke-LabCommand -PostInstallationActivity -ActivityName 'Post-installation' -ComputerName $PostInstallMachine.Name -AsJob -PassThru -NoDisplay
$postInstallJobs.Add($PostInstalljob)
}
```
## Environment details
PowerShell Version
```output
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.20348.558
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.558
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
AutomatedLab components
```output
Please paste the output of Get-Module AutomatedLab* -List | Select Name,Version in this output field
Get-Module AutomatedLab* -List | Select Name,Version
Name Version
---- -------
AutomatedLab 5.41.0
AutomatedLab.Common 2.1.223
AutomatedLab.Recipe 5.41.0
AutomatedLab.Ships 5.41.0
AutomatedLabDefinition 5.41.0
AutomatedLabNotifications 5.41.0
AutomatedLabTest 5.41.0
AutomatedLabUnattended 5.41.0
AutomatedLabWorker 5.41.0
```
Contributor guide
Assessment
This issue has not been assessed yet.