Luke K
Luke K

Reputation: 355

For Looping through ADuser List

I'm trying to use a script to go through the ADUser database and select certain people/data. Here's my current code:

$users = Get-ADUser -Filter * -Properties extensionattribute9,Displayname,mail 

$results = $users | ForEach-Object {
    if ($_.extensionattribute9 -like '*Smith*')
    {
      select Displayname,mail
    }
}
$results

Once this works, I'll be adding a few more foreach-object loops, getting more users that have certain other extensionattribute9 values. But for just this first one it runs with no errors, but doesn't display anything once it finishes. Am I doing something wrong with the extensionattribute9 variable? I tried the script without the $_., and it predictably said it couldn't recognize the term.

Upvotes: 0

Views: 1113

Answers (1)

DAXaholic
DAXaholic

Reputation: 35408

Change

select Displayname,mail 

to

$_ | select Displayname,mail  

Upvotes: 1

Related Questions