as a sample code:
$parentarray = @()
$getallvms = get-vm
foreach ($singlevm in $getallvms){
$array1 = "" | Select HardDisk
$harddisk = ($singlevm | Get-harddisk).Filename
$array1.HardDisk = $Harddisk
$parentarray += $array1
}
$ParentArray | Export-Csv -Path "C:\blah\whatever.csv"
In the CSV this will return a System.Object[] instead of multiple entries if there are multiple entries. I'm trying to figure out how to make this command show all the entries under the custom array... any help would be appreciated... Thanks!
Try like this.
Export-Csv doesn't know how to handle properties that do not hold simple values.
With the -join operator we convert the array of strings into a single string.
$parentarray = @()
$getallvms = Get-VM
foreach ($singlevm in $getallvms){
$array1 = "" | Select HardDisk
$harddisk = ($singlevm | Get-harddisk).Filename -join '|'
$array1.HardDisk = $Harddisk
$parentarray += $array1
}
$ParentArray | Export-Csv -Path "C:\blah\whatever.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
Export-Csv doesn't know how to handle properties that do not hold simple values.
With the -join operator we convert the array of strings into a single string.
$parentarray = @()
$getallvms = Get-VM
foreach ($singlevm in $getallvms){
$array1 = "" | Select HardDisk
$harddisk = ($singlevm | Get-harddisk).Filename -join '|'
$array1.HardDisk = $Harddisk
$parentarray += $array1
}
$ParentArray | Export-Csv -Path "C:\blah\whatever.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Works good enough for me.
Thanks a bunch.