Export to CSV return System.Object[] not the Data

Hi sreed,

Be sure to post any code in “

” tags. You’ve replaced all your code with dummy data. I was only showing the method of running the disks through a foreach loop. You’ll still need your data. I’m not sure how the code you posted ended up with the output you show. Anyways, I took your original code and adjusted. Please give it a shot. Please note that the first time one of these servers has a second NIC added, you’ll get duplicated entries for that server.

$report = @()
$vms = Get-Azvm
$nics = Get-AzNetworkInterface | ?{ $_.VirtualMachine -NE $null}
$disk = get-azdisk
foreach($nic in $nics)
{
$info = “” | Select ResourceGroupName,VmName,OStype,Interface,Adaptor,PrivIP,PublicIP,DiskName,DiskSize
$vm = $vms | ? -Property Id -eq $nic.VirtualMachine.id
$info.VMName = $vm.Name
$info.ResourceGroupName = $vm.ResourceGroupName
$info.Interface = $nic.name
$info.Adaptor = $nic.IpConfigurations.Name
$info.PrivIP = $nic.IpConfigurations.PrivateIpAddress
$info.PublicIP = $nic.IPConfigurations.PublicIpAddress
$info.OStype = $vm.StorageProfile.osDisk.osType
$count = 1
foreach($d in $disks){
Add-member -InputObject $info -NotePropertyName "Disk$($count)Name" -NotePropertyValue $d.name
Add-member -InputObject $info -NotePropertyName "Disk$($count)Size" -NotePropertyValue $d.disksizeGB
$count++
}
$report+=$info
}
$report | Sort-object PrivIP | Export-Csv -Path “c:\temp\AzureIP+Disk.Csv”

Good luck.

ResourceGroupName VmName OStype Interface Adaptor PrivIP PublicIP DiskName DiskSize
Server1 Probe Windows probe ipconfig1 10.0.0.1 System.Object[]
 

I changed the ResourceGroupName , VmName , and PrivIP to generic data but the output is the same. I still get the System.Object and nothing for DiskSize.

Does it show disk1name = object? I had a typo in it so I’m not sure how it gave you anything there. I recommend you work on running these commands one by one to find what each one outputs, what properties there are, how many there are, etc. I don’t have azure vms to test with so I can’t test any further. My guess based on the limited info here is you’ve got more than one disk and you’re trying to store them in one property. I tried showing some ways of looping over the drives, but you should confirm that is the actual issue. What is the output of

write-output $disks