Ah right lol, well if you wanted to use $_ and pipe it, you could do it like so:
Code:
$users = get-aduser -Filter * -SearchBase "DC=domain,DC=local" | Foreach-Object {write-host "Lol this guy's name is $($_.name), who'd seriously call their kid that"}
The $_ is just a placeholder for the current variable in the loop.
When you use a pipe "|" you're passing the results of the previous command to the next command.
So in this case, we're saying "get a list of all users with this criteria" then we want to pass the result of that request to our next command, which is "for each user we find, write out their name". How do we access the current user in that loop? With the placeholder $_ variable.
Oh, just in case it's unclear too, "$_.name" is enclosed by $() because it's inside a string.
i.e. if I just wrote "The name of this user is $_.name" then it would literally print out exactly what I wrote.
By adding the $() I can tell powershell that I want it to interpret $_.name as a variable
I love PS but it's things like that -Filter parameter that annoy me. Why can't they include a list of valid things you can filter by... you have to Google it, and it's not always that easy to find an up to date result.
Open up your PS prompt and type "get-help get-aduser"
You'll notice in the 3 paragraph description, one full paragraph is dedicated to the -Filter and -LDAPFilter parameters
and it says:
For more information about the Filter parameter syntax, see about_ActiveDirectory_Filter. If you have existing LDAP query strings, you can use the LDAPFilter parameter.
Voila, straight out says if you've already got a filter you run in AD, just whack it in to -LDAPFilter
And if we copy/paste "about_ActiveDirectory_Filter" into google and choose the first result back, we get this page:
https://technet.microsoft.com/en-us/library/hh531527(v=ws.10).aspx
That's a hell of a lot of info to include for just one parameter of one command, imagine if they had to do that for all parameters of all commands.