Solved

windows 2003 script to list service accounts with logon username

Posted on 2015-02-11
4
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Here's a look at newsworthy articles and community happenings during the last month.
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

623 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