Goal: Create a for or foreach loop to execute some code (in this case, just print x) for every user in an OU.
Im using powershell 2.0, with ActiveDirectory module.
So far: This is what I have (see below). It just prints out the X's for every user. But its not working how I want it to, instead I think it may be doing it for every line. So I get 6 X's for 'name', '—-', 'test1', 'test2', SPACE, SPACE.
$pool = Get-ADUser -Filter * -SearchScope Subtree -SearchBase "OU=Test,OU=Users,OU=jack,DC=Corp,DC=jill,DC=com" -Properties name | FT name
foreach ($user in $pool )
{ write-host "x"}
$pool
Result, the SPACE will be represented by a period (.) :
x
x
x
x
x
x
name
----
test1
test2
.
.
I am not sure why it does this.
If you have a better method or way of handling this, I'll be delighted in hearing it.
Best Answer
Your
$pool
will contain the output ofFormat-Table name
, the last step in the first line. TheFormat-*
cmdlets are used for displaying values on screen. You almost certainly don't want to feed a formatted table to yourforeach
loop.