So there are lot of things to address. First of all the foreach
loop works on array.
So your variable declaration is wrong. It has to be comma separated or it has to be in an array format.
like this
$input = "one", "two", "three"
$tests = "true", "false", "true"
OR
$input = @("one", "two", "three")
$tests = @("true", "false", "true")
Foreach
loop cannot operation on multiple arrays at a while ; in your case you should be using For
loop like
$input = "one", "two", "three"
$tests = "true", "false", "true"
foreach ($test in $tests) ## For looping through single array
{
Write-Host $test
}
If($input.Length -match $tests.Length) ## Forlooping through multiple arrays
{
For($i=0;$i -lt $input.Length; $i++)
{
"$($input[$i]) :: $($tests[$i])"
}
}
and for your Expected Format, it should be:
$input = "one", "two", "three"
$tests = @("true", "false", "true")
If($input.Length -match $tests.Length)
{
For($i=0;$i -lt $input.Length; $i++)
{
"$($input[$i])"
"$($tests[$i])"
}
}
OUTPUT:
one
true
two
false
three
true
PS: Now you can easily incorporate the Add-Member -InputObject $tests -MemberType NoteProperty -Name "Name" -Value $input
based on this logic.
Hope it helps.