Solved

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

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

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
Awesome ! that was it .. thanks !
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A procedure for exporting installed hotfix details of remote computers using powershell
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 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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now