$var =@( @{id=\"1\"; name=\"abc\"; age=\"1\"; },
@{id=\"2\"; name=\"def\"; age=\"2\"; } );
$properties = @(\"ID\",\"Name\",\"Age\") ;
$format = @();
foreach (
Accessing anything inside an Array of HashTables is going to be a bit finicky, but your variable expansion is corrected like this:
$var =@( @{id="1"; name="Sally"; age="11"; },
@{id="2"; name="George"; age="12"; } );
$properties = "ID","Name","Age"
$format = @();
$Var | ForEach-Object{
foreach ($p in $properties){
$format += @{
$p = $($_.($p))
}
}
}
You needed another loop to be able to tie it to a specific item in your array. That being said, I think that going with an array of Objects would be a much cleaner approach - but I don't know what you're dealing with, exactly.