How-to: List the background services [ServiceStatus.ps1]

List the services installed on one or more machines along with the status (running, stopped, disabled etc)
Call the script below passing the name of a text file containing the machines to query.
The output is written to a set of csv files in the current directory, one per machine: Services_<machine_name>.csv

Param($file)

function ServiceInfo{
    Param($mc)
    # Ping the machine to see if it is online
    $online=Test-Connection $mc -Quiet
    if ($online -eq $true)

    {
    # List services and service status
    Get-CimInstance win32_service -computer $mc  | Select-Object displayname,name,startmode,`
       status,state |  sort-object -property displayName | `
          export-csv -path "Services_$mc.csv" -noTypeInformation
    }
    else
    {
        Write-Verbose "     - Ping Failed!"
        Write-Host "Error: $mc not Pingable" -fore RED
    }
}

## Main

if($file -and (test-Path $file))
{
    foreach($comp in (get-Content $file))
    {
        Write-Host " +++ Processing Computer [$Comp] +++"
        ServiceInfo $comp
    }
}

Examples

Call the script above passing the name of a text file containing the machines to query, one per line.
Assuming the script above is saved in the current directory as ServiceStatus.ps1

PS C:\> ./ServiceStatus workstations.txt

“The Arab-Israeli conflict is also in many ways a conflict about status: it's a war between two peoples who feel deeply humiliated by the other, who want the other to respect them. Battles over status can be even more intractable than those over land or water or oil” ~ Alain de Botton

Related PowerShell Cmdlets

psinfo - List information about a system.
List of Windows 10 services with default status.
Get-Service - Get a list of services.


 
Copyright © 1999-2024 SS64.com
Some rights reserved