I wrote this script to generate a csv file:
$VMs = Get-AzureRmVM
$vmOutput = @()
$VMs | ForEach-Object {
$tmpObj = New-Object -TypeName PSObject
$tmpObj | Add-Member -MemberType Noteproperty -Name "VM Name" -Value $_.Name
$tmpObj | Add-Member -MemberType Noteproperty -Name "VM Type" -Value $_.StorageProfile.osDisk.osType
$tmpObj | Add-Member -MemberType Noteproperty -Name "VM Profile" -Value $_.HardwareProfile.VmSize
$tmpObj | Add-Member -MemberType Noteproperty -Name "VM OS Disk Size" -Value $_.StorageProfile.OsDisk.DiskSizeGB
$tmpObj | Add-Member -MemberType Noteproperty -Name "VM Data Disk Size" -Value $_.StorageProfile.DataDisks.DiskSizeGB
$vmOutput += $tmpObj
}
$vmOutput | export-csv C:\Users\***\data.csv -delimiter ";" -force -notypeinformation
But as the last column VM Data Disk Size stores one than more data (there can be multiple disks) in file they're presented as System.Object[]
. How can I force powershell to join this data into a single string?
I tried to add -join
parameter after $tmpObj
in line 9 ad after $vmoutput
in last line, but there were no satisfactory results.