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