I know this problem and have no real Solution for it.
But as workaround you could use
"$row3.VM \ $row3.VMInfo" | Out-File -append -path "c:\temp\testy.csv"
in your inner for each, and write the data manually as csv.
Array exporting to csv from powershell stack issue
-
01-07-2022 - |
質問
I am creating a reporting script in powercli for our vSphere. I am trying to make an array that i can export to csv. The problem i am having is i need to have multiple rows to input into the array, not just the same one over and over.
When i run in current format all that happens is the outermost row reports and none of the internal ones
Here is a mockup of what i want the script to do.
$report = @()
foreach($D in $data){
$row = "" | select Datacenter, datacenterInfo
$row.datacenter = "kam1"
$row.datacenterInfo = "12"
$report += $row
foreach($F in $D){
$row2 = "" | select folder, folderInfo
$row2.folder = "test"
$row2.folderInfo = "34"
$report += $row2
foreach($VM in $F){
$row3 = "" | select VM, VMInfo
$row3.VM = "test"
$row3.VMInfo = "56"
$report += $row3
}
}
}
$report | export-csv -path c:\temp\testy.csv -NoTypeInformation
Any Help Appreciated
data would hopefully come out as a csv in excel while looking like so
datacenter / datacenterinfo
test / 12
folder / folderinfo
test / 34
VM / VMInfo
test / 56
The real script would be detailing hundreds of VM's and folder though.
解決
所属していません StackOverflow