function Get-ServicesToStop { <# .SYNOPSIS Get the list of service names to be stopped. Focuses on chocolatey installed and Alkami named services (including Radium, Nag, etc) .PARAMETER SkipSubscriptionService Should include the subscription service? .PARAMETER SkipChocolateyServices Should include all services installed in the package library location? This may include non-Alkami services (think SDK, but also think FileBeats) .PARAMETER SkipAlkamiServices Should include all Alkami services? This may include services not in the package library location .OUTPUTS Returns the list of service names to be stopped #> [CmdletBinding()] [OutputType([string[]])] Param( [Parameter(Mandatory = $false)] [switch]$SkipSubscriptionService, [Parameter(Mandatory = $false)] [switch]$SkipChocolateyServices, [Parameter(Mandatory = $false)] [switch]$SkipAlkamiServices ) $servicesToStop = @() if (!$SkipChocolateyServices) { $rawservicesToStop = @(Get-ChocolateyServices | Where-Object { ($_.State -in ("Running", "StopPending") -and $_.Name -notmatch "Subscriptions") }) if (!(Test-IsCollectionNullOrEmpty $rawservicesToStop)) { $servicesToStop += $rawservicesToStop.Name } } if (!$SkipAlkamiServices) { $rawservicesToStop = @(Get-AlkamiServices) | Where-Object { $_.Status -in ("Running", "StopPending") } $legacyServicesToStop = @() $legacyServicesToStop += @($rawservicesToStop | Where-Object { $_.Name -notmatch "Subscriptions" }) #Add Subscription Service Last so it is the last one to be stopped if (!$SkipSubscriptionService) { $legacyServicesToStop += @($rawservicesToStop | Where-Object { $_.Name -match "Subscriptions" }) } if (!(Test-IsCollectionNullOrEmpty $legacyServicesToStop)) { $servicesToStop += $legacyServicesToStop.Name } } $filebeatServices = Get-FileBeatsService -ErrorAction SilentlyContinue if (!(Test-IsCollectionNullOrEmpty $filebeatServices)) { foreach($service in $filebeatServices) { if ($service.State -in ("Running", "StopPending")) { $servicesToStop += $service.Name; } } } return $servicesToStop | Select-Object -Unique }