Skip to content

Get-ServiceInfo

Windows: Retrieves detailed information about system services

#Requires -Version 5.1

[CmdletBinding()]
Param
(
    [Parameter(ValueFromPipeline = $true)]
    [string]$ComputerName = $env:COMPUTERNAME,

    [string]$Name,

    [string]$DisplayName,

    [string[]]$Properties = @('Name', 'DisplayName', 'Status', 'StartType', 'CanStop', 'CanPauseAndContinue')
)

Process {
    try {
        $getServiceParams = @{
            'ErrorAction' = 'Stop'
        }

        if (-not [string]::IsNullOrWhiteSpace($ComputerName)) {
            $getServiceParams.Add('ComputerName', $ComputerName)
        }

        if (-not [string]::IsNullOrWhiteSpace($Name)) {
            $getServiceParams.Add('Name', $Name)
        }
        elseif (-not [string]::IsNullOrWhiteSpace($DisplayName)) {
            $getServiceParams.Add('DisplayName', $DisplayName)
        }

        $services = Get-Service @getServiceParams

        if ($null -ne $services) {
            $result = $services | Select-Object -Property $Properties
            Write-Output $result
        }
    }
    catch {
        throw
    }
}

Specifies the name of the computer to query. Defaults to the local computer.

Specifies the name of the service to retrieve. Supports wildcards.

Specifies the display name of the service to retrieve. Supports wildcards.

Specifies the list of properties to include in the output. Use '*' for all properties.

An interactive directory of PowerShell scripts.