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=PingMachine $mc
    if ($online -eq $true)

    {
    # List services and service status
    get-wmiobject win32_service -computer $mc  | select 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
    }
}

function PingMachine {
   Param([string]$machinename)
   $pingresult = Get-WmiObject win32_pingstatus -f "address='$machinename'"
   if($pingresult.statuscode -eq 0) {$true} else {$false}
}

## Main

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

Example

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

“In any collection of data, the figure most obviously correct, beyond all need of checking, is the mistake” ~ Finagle's third law

Related:

psinfo - List information about a system
Get-Service - Get a list of services


© Copyright SS64.com 1999-2014
Some rights reserved