Solved

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

Posted on 2016-08-31
4
70 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
[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
  • 2
4 Comments
 
LVL 85

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 85

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Here's a look at newsworthy articles and community happenings during the last month.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

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