haripetrov
Contributor
Contributor

How to Display Information About FileName of a Disk?

I am trying to obtain information about all disks which are using "nonpersistent" mode with Get-View. Everything is working with the exception of @{N="Filename";E={$vm.Config.Hardware.Device.Backing.FileName}}

$VMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template}

$Result = @(ForEach ($vm in $VMs){

    $vdisk = $vm.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk] -and ($_.Backing.DiskMode -eq "nonpersistent" -or $_.Backing.DiskMode -eq "independent_nonpersistent")}

    if ($vdisk){

        $vdisk | Select @{N="VM";E={$vm.Name}},

            @{N="NonPersistentMode";E={$_.DeviceInfo.Label}},

            @{N="CapacityGB";E={$_.capacityInKB/1024/1024}},

            @{N="Filename";E={$vm.Config.Hardware.Device.Backing.FileName}}

    }

})

$Result

This script is originally inspired by this one:

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent" -or $_.Persistence -eq "IndependentNonPersistent"} } | Select Parent, Name, CapacityGB, Filename, DiskType, Persistence, ScsiCanonicalName | Export-CSV VMs_Persistent_Mode.csv -NoTypeInformation -UseCulture

I can see that in https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.device.VirtualDevice... we have property "FileName" but I don't know how to call it in this case.

Reply
0 Kudos