I'm a noob when it comes to Powershell so i'm wondering how to solve this. Essentially, I have a script where I obtain details for a person using a foreach loop. The problem is, I want to put this into a table of columns and rows that looks like this:
Age | eyecolour | gender |
---|---|---|
46 | green | male |
As it stands, I have a script which creates an object, but it's not right. The object is getting created per person and I don't want that. I need rows to be added per person. Also it's not in table format and needs to be exported to Excel. Any ideas on the best approach?
Thanks.
$people = #variable containing multiple people
foreach ($person in $people){
$age = #some get command
$eyecolour = #some get command
$gender = #some get command
$object = new-object psobject -Property @{
age = $age
eyecolour = $eyecolour
gender = $gender
}
Write-Host $object
}
CodePudding user response: