function Start-ServicesChocolateyOnly { <# .SYNOPSIS Starts Chocolatey services by tier. .DESCRIPTION Starts Chocolatey services by tier. Maximum parallelism can be controlled with the maxParallel parameter .PARAMETER maxParallel [int] Can be an int value from 1 to [int]::MaxValue. Limits service start parallelism .EXAMPLE Start-ServicesChocolateyOnly [Get-ChocolateyServices] : Finding services installed out of the chocolatey path: C:\ProgramData\chocolatey [Get-ChocolateyServices] : Found 4 chocolatey services. [Get-ChocolateyServicesToStart] : Found 4 Chocolatey Services [Start-ServicesChocolateyOnly] : Starting 2 Services in Tier 0 [Start-ServicesInParallel] : Starting Service Alkami.Services.Subscriptions.Host [Start-ServicesInParallel] : Starting Service Alkami.MicroServices.Broker.Host [Start-ServicesInParallel] : Done Starting Services [Start-ServicesChocolateyOnly] : Tier 0 took 00:00:27.3150594 to start [Start-ServicesChocolateyOnly] : Starting 1 Services in Tier 1 [Start-ServicesInParallel] : Starting Service Alkami.MicroServices.Authorization.Service.Host [Start-ServicesInParallel] : Done Starting Services [Start-ServicesChocolateyOnly] : Tier 1 took 00:00:14.5806190 to start [Start-ServicesChocolateyOnly] : Starting 1 Services in Tier 2 [Start-ServicesInParallel] : Starting Service Alkami.MicroServices.Features.Beacon.Host [Start-ServicesInParallel] : Done Starting Services [Start-ServicesChocolateyOnly] : Tier 2 took 00:00:13.4367245 to start [Start-ServicesChocolateyOnly] : Done starting services. #> [CmdletBinding()] [OutputType([void])] Param( [Parameter(Mandatory = $false)] [ValidateRange(1, [int]::MaxValue)] [int]$maxParallel = 10 ) $loglead = Get-LogLeadName [array]$stoppedChocolateyServices = Get-ChocolateyServicesToStart if (Test-IsCollectionNullOrEmpty -Collection $stoppedChocolateyServices) { Write-Warning "$logLead : No Chocolatey Services Found to Start" return } # This takes all stopped Choco services, groups them by the property Tier, then forces Tier as an Int to sort numerically ascending # to enforce Tier 0 starts before Tier 1 before Tier 2, etc. $groupedChocolateyServices = $stoppedChocolateyServices | Group-Object -Property Tier | Sort-Object @{e={$_.Name -as [int]}} foreach ($group in $groupedChocolateyServices) { $services = $group.Group | Select-Object -ExpandProperty ServiceName Write-Host "$logLead : Starting $($group.Count) Service(s) in Tier $($group.Name)" $tierStopWatch = [System.Diagnostics.StopWatch]::StartNew() Start-ServicesInParallel -serviceNamestoStart $services -maxParallel $maxParallel Write-Host "$logLead : Tier $($group.Name) took $($tierStopWatch.Elapsed) to start" $tierStopWatch.Stop() } Write-Host "$loglead : Done starting services." }