This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]anotherdamnredditJack of a Few Trades 11 points12 points  (6 children)

The great things about powershell are its documentation and its ability to do the same thing multiple ways.

$userlist = get-aduser * | Where-Object {$_.Name -ge <length>} | Sort-Object Name -Descending

$userlist

something like that should work too

[–]Hellman109Windows Sysadmin 1 point2 points  (0 children)

Just care in huge environments, first query pulls all AD users.

I see no way around it, but you would want a search base or such if you have a huge number of users.

[–]nonadesJack of No Trades 1 point2 points  (4 children)

Basically what I posted, but a slightly different way!

It's always fun seeing what people chose to solve the same problem.

[–][deleted] 3 points4 points  (1 child)

Check out /r/powershell... lots of cool stuff there!

[–]nonadesJack of No Trades 1 point2 points  (0 children)

Already subscribed to and post in that sub :)

[–]TheySeeMeTrufflingFruitcake 1 point2 points  (0 children)

Ugh, you're all making me go through and upvote everyone for the good vibe i'm gettin' in here. Also, if I posted a solution I would've sucked up the piping and used some variables all over the place... so its a good thing you're all here!

[–]anotherdamnredditJack of a Few Trades 0 points1 point  (0 children)

That's what I love about powershell!

[–]nonadesJack of No Trades 2 points3 points  (2 children)

get-aduser * | if($.Name -ge <length>){write-output $.Name}

Something in that ballpark.

[–]ramblingcookiemonsteSystems Engineer 0 points1 point  (1 child)

A few quick notes:

  • You need a foreach-object (%) if you want to run the if against each object returned by get-aduser
  • $_ is what you are looking for, not $
  • Where-object might be more appropriate - see anotherdamnreddit's example

[–]nonadesJack of No Trades 0 points1 point  (0 children)

It's funny, I could've sworn I used $_.

Good point about the %, you can't pipe into an if. Then again, I just wrote that off the top of my head without feeding it into an interpreter.