Solved

windows 2003 script to list service accounts with logon username

Posted on 2015-02-11
4
72 Views
Last Modified: 2015-02-12
Hello Everyone,

I am look to see if any domain admin accounts are being using to run services, so I am looking for a script that can list out all the services on a server with the logon name.  Can anyone help?

Thanks,

Bill
0
Comment
Question by:bjennings
  • 2
4 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40603887
@echo off
for /f "tokens=1-2" %%a in ('sc query') do (if "%%a" equ "SERVICE_NAME:" sc qc %%b)

Open in new window

0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40604485
This will create a csv file with all services that are running under a domain account:
@echo off
setlocal enabledelayedexpansion
set LogFile=%~dpn0.csv
>"%LogFile%" echo "DisplayName","ServiceName","Account"
for /f "tokens=1* delims=: " %%a in ('sc.exe query ^| find.exe /i "_NAME:"') do (
	set %%a=%%b
	if "%%a"=="DISPLAY_NAME" (
		for /f "tokens=1* delims=: " %%s in ('sc.exe qc "!SERVICE_NAME!" ^| find.exe /i "SERVICE_START_NAME"') do (
			set %%s=%%t
			set DomainAccount=False
			echo '!DISPLAY_NAME!' ^('!SERVICE_NAME!'^): '!SERVICE_START_NAME!'
			if not "!SERVICE_START_NAME:%USERDOMAIN%=!"=="!SERVICE_START_NAME!" (
				set DomainAccount=True
			) else (
				if not "!SERVICE_START_NAME:@=!"=="!SERVICE_START_NAME!" (
					set DomainAccount=True
				)
			)
			if /i "!DomainAccount!"=="True" (
				>>"%LogFile%" echo "!DISPLAY_NAME!","!SERVICE_NAME!","!SERVICE_START_NAME!"
			)
		)
	)
)

Open in new window

0
 

Author Closing Comment

by:bjennings
ID: 40605953
Worked great!!!
0
 

Author Comment

by:bjennings
ID: 40605954
Thanks you guys for your help!!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question