Searching for service running by a service account on all servers

I am trying to find any server across the domain, using a specific service account to run a service.  When I run

get-wmiobject "win32_service" -Filter "StartName = 'domain\\account'"

from the one server I know is using the account I return the list of services running under that account. 

However when I try below I get No Service Found on every server even the one server I know is using the account.

$servers=Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -SearchBase "OU=XXXX,OU=XXXX,DC=XXXX,DC=XXXX,DC=XXXX,DC=XXXX" -property *  
ForEach ($server in $servers){ 
$Services=get-wmiobject "win32_service" -Filter "StartName = 'domain\\account'"  
If($Services -ne $null){ 
Write-host $Services 
} 
Elseif ($Services -eq $null){ 
Write-Host "No Services found on Server $server" 
}  
}

I'm not sure what I am doing wrong?

Thanks for any help you can provide


August 24th, 2015 2:42pm

Hi,

You're not using the -ComputerName parameter:

http://ss64.com/ps/get-wmiobject.ht

August 24th, 2015 2:49pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics