Solved

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

Posted on 2013-05-16
4
436 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
  • 2
  • 2
4 Comments
 
LVL 69

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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
In-place Upgrading Dirsync to Azure AD Connect
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

808 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