Solved

script or cmdlet to retrieve service accounts in AD, and export to a CSV file

Posted on 2016-08-31
4
46 Views
Last Modified: 2016-09-08
Hello Team,

My customer runs a Windows 2008 Forest/domain functional level with multiple sites, and OUs, and one of these OUs
is dedicated to host service accounts.

Their standard convention name for any service accounts should start with "SVC" defined on the user logon name and display name

I have following scenario, and need to know to get a script, or cmdlet to retrieve any service accounts under a specific OU which logon name or display name may not contain "SVC"

The report should be exported to a CSV, and contain only those service accounts that were created with a different standard for logon name or display name

Please, test the script on your lab before posting here
0
Comment
Question by:Jerry Seinfield
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41778248
Get-ADUser -Filter "(SamAccountName -notlike 'SVC*') -or (DisplayName -notlike 'SVC*')" -Property DisplayName -SearchBase "ou=Service Accounts,ou=ServiceAccounts,ou=SomeOU,dc=acme,dc=com" |
	Select-Object SamAccountName, DisplayName |
	Export-Csv C:\Temp\BadServiceAccounts.csv

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 41778420
can you please provide an example of the seachbase using your cmdlet above? Need to know full path
0
 
LVL 83

Expert Comment

by:oBdA
ID: 41778434
There is an example right there? The Distinguished Name of the OU in question? I wouldn't know the full path to your customer's dedicated service account OU.
If the name of this OU is unique (for example 'Service Accounts'), you can use Get-ADOrganizationalUnit:
$DN = (Get-ADOrganizationalUnit -Filter "Name -eq 'Service Accounts'").DistinguishedName
Get-ADUser -Filter "(SamAccountName -notlike 'SVC*') -or (DisplayName -notlike 'SVC*')" -Property DisplayName -SearchBase $DN |
	Select-Object SamAccountName, DisplayName |
	Export-Csv C:\Temp\BadServiceAccounts.csv

Open in new window

1
 

Author Comment

by:Jerry Seinfield
ID: 41790186
zZX
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

910 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

21 Experts available now in Live!

Get 1:1 Help Now