Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

windows 2003 script to list service accounts with logon username

Posted on 2015-02-11
4
Medium Priority
?
76 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 25

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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
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…

688 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