Searching for service running by a service account on all servers
i trying find server across domain, using specific service account run a service. when run
get-wmiobject "win32_service" -filter "startname = 'domain\\account'"
from 1 server know using account return list of services running under account.
however when try below i get no service found on every server 1 server know using 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 doing wrong?
thanks can provide
hi,
you're not using -computername parameter:
http://ss64.com/ps/get-wmiobject.html
edit: also, don't need -properties *. i'd rewrite script use foreach-object loop instead of foreach. personal preference though, it's easier output results.
Windows Server > Windows PowerShell
Comments
Post a Comment