Solved

Power Shell - Quest - How to pull all samAccountNames that are 7 or 8 characaters long

Posted on 2013-05-16
4
439 Views
Last Modified: 2013-05-16
Hi EE

I am trying to search for all samAccountNames in my environment that are only 7 or 8 characters long .. any idea how I can do this with Quest Tools ? or any other tool ?
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
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 39171947
get-qaduser | ? { $_.SamAccountName.Length -eq 7 -or $_.SamAccountName.Length -eq 8 }

Open in new window

should give you all those user objects.
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39172016
Thanks Qlemo

Any way to modify it so when I output the file it only gives me the samAccountName ?
It is outputting all the attributes below and since I have 200K plus accounts this may take longer ?


get-qaduser | ? { $_.SamAccountName.Length -eq 7 -or $_.SamAccountName.Length -eq 8 } | Export-CSV 7or8.csv

Exported all these...
objectClass      objectSid      whenCreated      objectGUID      whenChanged      edsvaNamingContextDN      l      facsimileTelephoneNumber      givenName      mail      sn      mobile      physicalDeliveryOfficeName      telephoneNumber      st      wWWHomePage      City      Company      Department      Email      Fax      FirstName      HomePhone      Initials      LastName      LogonName      Manager      MobilePhone      Office      Pager      PhoneNumber      PostalCode      PostOfficeBox      PrimaryGroupId      StateOrProvince      StreetAddress      Title      WebPage      HomeDirectory      HomeDrive      ProfilePath      LogonScript      UserPrincipalName      TsProfilePath      TsHomeDirectory      TsHomeDrive      TsAllowLogon      TsRemoteControl      TsMaxDisconnectionTime      TsMaxConnectionTime      TsMaxIdleTime      TsReconnectionAction      TsBrokenConnectionAction      TsConnectClientDrives      TsConnectPrinterDrives      TsDefaultToMainPrinter      TsWorkDirectory      TsInitialProgram      AccountExpires      PasswordLastSet      PasswordAge      PasswordExpires      LastLogonTimestamp      LastLogon      LastLogoff      AccountIsDisabled      AccountIsLockedOut      PasswordNeverExpires      UserMustChangePassword      AccountIsExpired      PasswordIsExpired      AccountExpirationStatus      PasswordStatus      DeprovisionStatus      NTAccountName      SamAccountName      Security      Domain      LastKnownParent      MemberOf      NestedMemberOf      Notes      AllMemberOf      Keywords      ProxyAddresses      PrimarySMTPAddress      PrimarySMTPAddressPrefix      PrimarySMTPAddressSuffix      PrimaryX400Address      PrimaryMSMailAddress      PrimaryCCMailAddress      PrimaryMacMailAddress      PrimaryLotusNotesAddress      PrimaryGroupWiseAddress      EmailAddressPolicyEnabled      Path      DN      CanonicalName      CreationDate      ModificationDate      ParentContainer      ParentContainerDN      Name      ClassName      Type      Guid      Sid      Description      DisplayName      OperationID      OperationStatus      Cache      Connection      DirectoryEntry
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39172093
Just pipe the result thru select-object prior to exporting:
get-qaduser |
   ? { $_.SamAccountName.Length -eq 7 -or $_.SamAccountName.Length -eq 8 } |
   select samAccountname | Export-CSV 7or8.csv

Open in new window

That's the same as for any other object you want to restrict the visible properties.
0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39172264
Awesome ! that was it .. thanks !
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
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…
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 to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

617 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