- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Device property is an array, so you will have to find the correct entry.
Perhaps based on the Label, something like this
$hd = $vm.Config.Hardware.Device | where{$_.Info.Label -eq 'Hard Disk 1'}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will continue to search for this information. ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let me know if you can find it, otherwise I can give you a sample script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have not managed to find the information so far. I would appreciate it if you could share your sample script here.
P.S. Would it be possible for you to tell me how you format your code in this way (using color format)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try something like this
$diskModes = [VMware.Vim.VirtualDiskMode]::independent_nonpersistent,[VMware.Vim.VirtualDiskMode]::nonpersistent
foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device -Filter @{'Config.Template'='False'})){
$vm.Config.Hardware.Device |
where{$_ -is [VMware.Vim.VirtualDisk] -and $diskModes -contains $_.Backing.DiskMode} |
Select @{N="VM";E={$vm.Name}},
@{N="Disk";E={$_.DeviceInfo.Label}},
@{N="Mode";E={$_.Backing.DiskMode}},
@{N="CapacityGB";E={$_.capacityInKB/1MB}},
@{N="Filename";E={$_.Backing.FileName}}
}
To get the syntax highlighted code, I currently use the PowerShell ISE addon from Windows PowerShell V3 ISE: Copy As HTML Add-On
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, again. The script is working as expected.
I will try this addon in question.