Hello guys and Happy New Year!!
I have a question about multi-valued attributes and how to export them as csv.
While I know how to work with multi-valued attributes I’ve come to a dead end with this script that I am writing.
Here are the details:
I have to export a csv file that will contain VMName, HardDiskName, FileName etc.
At first I tried this approach (1):
$hdd = Get-HardDisk -VM “vmname” -DiskType RawPhysical| select Parent, Name
$props = @{‘VMName’ = $hdd.parent
‘HDDName’ = $hdd.name
}
$obj = New-Object -TypeName PSObject -Property $props
#Write-Output $obj
$obj | Export-Csv vm.csv -NoTypeInformation
I quickly realised that this approach won’t work because I am dealing with multi-valued attributes and I won’t be able to export them properly.
…than I tried this (approach 2)
$hdd = Get-HardDisk -VM “vmname” -DiskType RawPhysical| select @{Name=‘VmName’;Expression={[string]::join(“;”, ($.parent))}}, @{Name=‘HDDName’;Expression={[string]::join(“;”, ($.name))}}
$props = @{‘VMName’ = $hdd.parent
‘HDDName’ = $hdd.name
}
$obj = New-Object -TypeName PSObject -Property $props
#Write-Output $obj
$obj | Export-Csv vm.csv -NoTypeInformation
Needles to say that this did not work either
Some attributes are not multi-valued and I could get them with approach 1 but I cannot get the multi-valued attributes.
if I do this
$hdd = Get-HardDisk -VM svwdbn21 -DiskType RawPhysical| select @{Name=‘VmName’;Expression={[string]::join(“;”, ($.parent))}}, @{Name=‘HDDName’;Expression={[string]::join(“;”, ($.name))}},`
@{Name=‘FileName’;Expression={[string]::join(“;”, ($.filename))}}, @{Name=‘DeviceName’;Expression={[string]::join(“;”, ($.devicename))}},`
@{Name=‘CanonicalName’;Expression={[string]::join(“;”, ($_.ScsiCanonicalName))}}| Export-csv test.csv
I can get almost all details I need except LUN info which I am getting it with the following piece of code:
$hdd = Get-HardDisk -VM “vmname” -DiskType RawPhysical| select parent, name, filename, devicename, ScsiCanonicalName
$Lun = Get-SCSILun $hdd.SCSICanonicalName -VMHost $vm.vmhost
$lunpaths=$lun|Get-ScsiLunPath
$luns = $lunpaths | select name, sanid, State, Preferred
$luns
… and here is where I got really stuck.
I need a way to combine in one csv file all the multi-valued atributes and LUN info which right now is stored in $luns.
Any ideas/help will be much appreciated.
Thank you