Solved

windows 2003 script to list service accounts with logon username

Posted on 2015-02-11
4
69 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 23

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 82

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
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 tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 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

19 Experts available now in Live!

Get 1:1 Help Now