Solved

windows 2003 script to list service accounts with logon username

Posted on 2015-02-11
4
71 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 83

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This article runs through the process of deploying a single EXE application selectively to a group of user.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now