I see a couple of mistakes.. one is you forgot the $ in $URLS in the second,
but the main one is a common confusion with powershell..
foreach($a in $y) in a LANGUAGE CONSTRUCT of powershell, while foreach-object is a CMDLET that just happens to come with powershell which implements funtional programming MAP concepts http://en.wikipedia.org/wiki/Map_%28higher-order_function%29 .
to muddy the waters foreach-object has an alias set as foreach as well..
so when you are doing a straight language loop you can use foreach($i in $y)
but when you are using the pipeline you use foreach-object
i.e
1..10 | foreach-object { $_ * $_ } will output the square of whatever is coming through the pipeline..
there are different aliases for foreach-object , namely foreach and % so the above line could also be written
1..10 | foreach { $_ * $_ }
or
1..10 | % { $_ * $_ }
you can read the help in powershell, i think about_foreach and foreach-object's help
foreach-object can also take in some scriptblocks to run at the start, and at the end as well..
i.e what you saw above is putting the scriptblock as the -process parameter
so
1..10 | foreach-object -process { $_ * $_ }
is exactly the same but you could do
1..10 | foreach-object -start { write-host "being of loop" } -process { $_ * $_ } -end {write-host "end of loop " }
or you can just have the parameters implicit by order
1..10 | foreach-object { write-host "being of loop" } { $_ * $_ } {write-host "end of loop " }
-Karl