Sorry for the title, I'm not quite sure how to explain what I see.
Code example:
$SampleValues = 1..5
$Result = "" | Select ID
$Results = @()
$SampleValues | %{
$Result.ID = $_
$Results += $Result
}
$Results
It is pretty simple:
- Create an array with 5 numbers to be used in a loop
- Create a temporary variable using NoteProperty named ID
- Create an empty array to store the results
- Swipe through each of the 5 numbers, assigning them a temporary variable, and then adding it to the array.
The expected result is 1,2,3,4,5, but at startup it returns 5,5,5,5,5
, script, , , . , $Results, , . , $Script: $Global: scope .
- , $Result .
$SampleValues = 1..5
$Results = @()
$SampleValues | %{
$Result = "" | Select ID
$Result.ID = $_
$Results += $Result
}
( 1,2,3,4,5 ). , $Results $Result, ? $Result , , , , $Result ( , , ) , .
- , , . , , , .