Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-31
4
Medium Priority
?
97 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 85

Accepted Solution

by:
oBdA earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

916 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