Using Invoke-SQLCMD, I get a single column list of values. The type is Object.Array
I then start a While Loop while there are objects in the array:
WHILE ($ary.Item.Count > 0)
{
–Do some stuff–
$ary = $ary | Where {$_.name -ne $chkParams.column1} | Select -Property name
}
This works fine until there is only 1 value left in the list. Then $ary is no longer an Array; it is just an object. So the $ary.Item.Count returns 0 even though there is still one value left in the list.
Basically, I retrieve a list of values from a SQL Query. I want to iterate through the list, removing one at a time until there are none left then exit the loop.
When you want to access a property of an object while embedding it in a string (or evaluate the results of any other expression), you have to use the subexpression operator: $(). Try this: