Solved

Search domain for accounts that end with a particular letter

Posted on 2014-03-13
12
357 Views
Last Modified: 2014-03-13
Hi EE ..

This is weird one .. I would like to have a PS script that will search for all accounts that end with the letter T , need to search the entire domain , except for the Disabled Accounts OU .

The output file to give me the SamAccountName,Name, title ,Company
0
Comment
Question by:MilesLogan
[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
  • 7
  • 5
12 Comments
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927112
get-aduser -filter * -properties * | ? {$_.samaccountname -like "*t" -and $_.enabled -eq $true} | select-object SamAccountName,Name, title ,Company | export-csv "path.csv"
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39927127
Hi Justing .. but this will search in the Disabled Accounts OU also .. I need it to not search that OU ..
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927144
no it will not it is only $_.enabled eq $true.
0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927157
if you want to filter a OU add the filter on it

get-aduser -filter {distinguishedName -ne "CN=Users,DC=domain,DC=domain,DC=domain} -properties * | ? {$_.samaccountname -like "*t" -and $_.enabled -eq $true} | select-object SamAccountName,Name, title ,Company | export-csv "path.csv"
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39927159
well .. see thats part of my issue also .. Accounts outside of the Disabled Accounts OU will be both enabled and disabled .. so I need the query to not look at the enabled status .. I just need all "t" accounts outside of the Disabled Accounts OU
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 39927169
get-aduser -filter {distinguishedName -notlike "*,OU=disabled OU,DC=domain,DC=domain,DC=domain} -properties * | ? {$_.samaccountname -like "*t" -and $_.enabled -eq $true} | select-object SamAccountName,Name, title ,Company | export-csv "path.csv"

this will exclude the users in the disabled OU and it has $_.enabled -eq $true which will only return account that is enabled. any disabled accounts will not be included in the result.
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39927188
Thanks, I will give this a try in a few mins ..

CanI remove "-and $_.enabled -eq $true" from the search so it does include disabled accounts ?
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927204
yes it will include the disabled at that point
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927238
I changed it a bit

get-aduser -filter * -properties * | ? {$_.samaccountname -like "*t" -and $_.enabled -eq $true -and distinguishedName -notlike "*,OU=disabled OU,DC=domain,DC=domain,DC=domain} | select-object SamAccountName,Name, title ,Company | export-csv "path.csv"

for some reason the filter doesn't do the job.
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39927277
HI Justin ..
I left the search as you listed and I just modified the OU path and file name and received the error below .


The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39927296
you are missing the "

"ou=path",dc=so,dc=so,dc=so"
0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39927957
Thanks so much man !!! wow
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

719 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