One of the things clients ask me about all the time is “How do I find out what service accounts are in use on my servers?”
I can’t tell you how many times I’ve spoken to a customer and they have no idea what accounts are out there running services, and in particular where the Administrator account is being used to run services! The good thing is that with Active Directory this is pretty easy to get. All you need to do is use the script below to get a nice csv file that contains all of the non-normal service accounts. What is a “non-normal” service account?, you might ask. Anything that is not: LocalSystem NT AUTHORITYLocalService NT AUTHORITYLocal Service NT AUTHORITYNetworkService NT AUTHORITYNetwork Service The script works by finding all the AD computer objects that have “Server” in their OperatingSystem attribute. Then it checks to see if the server is alive or not, and if it is alive to check the services running on the server using WMI. Once it has the services it will output any service that does not run as one of the normal service accounts. If you have accounts that you considfer “normal” just add them to the $systemservicenames array.
You will see an error in the console if you are running it on a server since the WMI query will balk at using credentials for connecting to the local machine.