Solved

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

Posted on 2013-05-16
4
433 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

786 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