Solved

GetADuser -filer sAMAccountName with 5 character

Posted on 2013-01-23
4
1,281 Views
Last Modified: 2013-01-23
Hi,
Is it possible to include a filter for sAMAccountName with exactly 5 character in the below script. My goal is to select users with 5 character usernames that has an email.

Get-ADUser -Filter {mail -like '*@*'} -SearchBase......

Regards
0
Comment
Question by:pacch
[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 40

Expert Comment

by:Subsun
ID: 38809051
Try with..
Get-ADUser -Filter {mail -like '*@*'} | ? {$_.Samaccountname.length -eq 5}
0
 

Author Comment

by:pacch
ID: 38809407
Tanks for the reply - i get this error when trying

Where-Object : A parameter cannot be found that matches parameter name 'SearchB
ase'.
At line:1 char:109
+ $users += Get-ADUser -Filter {mail -like '*@*'} | ? {$_.Samaccoun
tname.length -eq 5} -SearchBase <<<<  "OU=myOU,DC=
myDCl,employeeType,@{n='OU';e={$_.canonicalname -replace "/$($_.cn)",""}}
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBi
   ndingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.WhereObjectCommand

Regards
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38809425
It should be like..
Get-ADUser -Filter {mail -like '*@*'} -SearchBase "OU=myOU",DC=myDC,DC=com" -Properties * | ? {$_.Samaccountname.length -eq 5} | Select-Object sAMAccountName,givenName,sn,mail,employeeType,company,Department,@{n='OU';e=@{n='OU';e={($_.canonicalname -Split "/")[-2]}} | Export-Csv "C:\file.csv" -Encoding "Unicode"

Open in new window

0
 

Author Closing Comment

by:pacch
ID: 38809505
Works Thanks!!
0

Featured Post

What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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