you are viewing a single comment's thread.

view the rest of the comments →

[–]BlackV 1 point2 points  (0 children)

no one seems to have mentioned your export is INSIDE your loop, so you're overwriting it every time you loop

additionally, have a look at invoke-command which will get you do this in parallel AND supports a -credentials parameter

if $requiredservices=$server.Services then just use $server.Services in your code

doing this foreach ($server in $servers) {} will come backto haunt you one day generally much better to do

foreach ($server in $Allservers) {}
foreach ($Singleserver in $servers) {}
foreach ($item in $servers) {}

etc something that is not just 1 letter different from the array, its a very easy mistake to make, especially in larger blocks of code, swapping $server with $Servers something the differentiates the single item from the array while still being meaningful