Return list of samaccounts with length of 3 or less

Hello,

If I run: 

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize unlimited | select samaccountname

It will out put all the samaccounts. What I need to be able to do is list only those that are 3 characters or less long. 

Doing this in powershell, tried working with length such as: 

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize unlimited | select samaccountname | select $_.length -lt 3

However, it doesn't work. 

Anyone have experience with this? 

February 2nd, 2015 5:44pm

Use Where-Object. For example:

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize unlimited | select samaccountname | where-object {$_.samaccountname.length -le 3}
And use -le rather than -lt.
Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2015 6:41pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics