function Get-ServiceNamesByFragment { <# .SYNOPSIS Get the service names of all services matched by the fragment passed in. .PARAMETER Name A name fragment to match against .PARAMETER ReturnNullIfNotFound Used to alter legacy behavior .OUTPUTS Will return the all service names that match #> [CmdletBinding()] [OutputType([System.String])] Param( [Parameter(Mandatory=$false)] [Alias("Fragment")] [string]$Name = "", [switch]$ReturnNullIfNotFound ) $logLead = (Get-LogLeadName) Write-Verbose ("$logLead : Checking for service names") $services = @((Get-Service) | Where-Object { (($_.DisplayName -match $Name) -or ($_.Name -match $Name)) }) if (Test-IsCollectionNullOrEmpty $services) { if ($ReturnNullIfNotFound) { return $null } return 'Not Installed' } return ($services).ServiceName }