Creates a list of devices from Active Directory query, pings each device, queries each device for a specific service running that responded with successful ping reply.  Outputs Service Status for each device to screen.  I modify and use versions of this script to handle several different needs.

No arguments. Not tested in shell environment.  I typically use within ISE environment.  Have not tested on W2K8 or Windows 7.

PowerShell
Edit|Remove
$erroractionpreference = "SilentlyContinue"
[collections.sortedlist]$Hash = @{}
    # Optional filters for specific OS level
    $w2k3OS = "5.2 (3790)"
    $xpOS = "5.1 (2600)"
    $vistaOS = "6.0 (6001)"
    
    $strFilter = "(&(objectCategory=Computer)(operatingsystemversion=$w2k3OS))"

    $root = [ADSI]"LDAP://RootDSE"
    $props = "name", "adspath"
    $Searcher = new-Object System.DirectoryServices.DirectorySearcher($root,$strFilter,$props) 
    $Searcher.PageSize = 1000 
    $colResults = $Searcher.findAll() 

foreach ($i in $colResults) {
    [string]$computer = $i.Properties.name
    write-host "Checking $computer `t" -nonewline

    $ping = & {ping -n 1 $computer} 
    [string]$pingReply = $ping
    if(($pingReply.contains("Reply from")) -and !($pingReply.contains("Destination host unreachable"))){
        $wmi = get-wmiobject -namespace "root\CIMV2" -query "select * from win32_service where Name='WINS'" -computer $computer -ErrorVariable $wmiError
        if(!($wmiError)){
            if($wmi.State){ $Hash.Add($computer,$wmi.State) }
            else{ $Hash.Add($computer,"Not Installed") }
        }
        else{ $Hash.Add($computer,"Error: Unable to Query") }
    }
    else { $Hash.Add($computer,"Unresponsive") }
}
$Hash