1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# # Get-ServiceNames.ps1 [-ServicePattern 'screen'] # # This script retrieves and displays a list of all services on the local machine, # including their service names, display names, and current statuses. # # NOTE FORMATTING IN ABOVE EXAMPLE -> screen is the text, and * are wildcards, and '' only needed if spaces. # param ( [string]$ServicePattern = '*' ) # Retrieve all [matching] services $services = Get-Service -ErrorAction SilentlyContinue | # Filter services based on the display name pattern (case-insensitive) Where-Object { $_.DisplayName -like $ServicePattern } | # Select desired properties Select-Object @{Name='ServiceName';Expression={$_.Name}}, DisplayName, Status #Check if any services were found if ($services) { # Sort and display the services $services | Sort-Object ServiceName | Format-Table -AutoSize } else { Write-Host "No services found matching the pattern '$ServicePattern'." } |