Hi all,
I´m trying to write a small script which should provide an VM-Report into Gridview. The following Lines are the status quo:
$vms = Get-Cluster ClusterName | Get-VM *
$vmreport = $vms | % {Get-View -ViewType virtualmachine -Filter @{"Name"=$_.Name} |
Select @{N="VMName";E={$_.Name}},
@{N="VM-OSID";E={$_.Config.GuestID}},
@{N="VM-OS";E={$_.Config.GuestFullName}},
@{N="VM-Version";E={$_.Config.Version}},
@{N="VM-CPUs";E={$_.Config.Hardware.NumCpu}},
@{N="VM-CPU-Sockets";E={$_.Config.Hardware.NumCoresPerSocket}},
@{N="VM-Memory(MB)";E={$_.Config.Hardware.MemoryMB}},
@{N="VM-Datastore";E={$_.Config.DatastoreUrl.Name}},
@{N="VM-NIC-Networkname";E={$_.Guest.Net.Network}},
@{N="VM-NIC-MAC-Adress";E={$_.Guest.Net.MacAddress}},
@{N="VM-NIC-IP-Adress";E={$_.Guest.Net.IPAddress}},
@{N="VM-Annotation";E={$_.Config.Annotation}}
}
$vmreport | Out-Gridview
What i need additionally is:
- Harddisk-Count of VM
- Size of Virtual-Disk
- path to virtual-Harddisk
- type of virtual-Hardisk ( some VMs have several RDM´s )
- if possible: SCSI-Canonical-Name of RDM-Disk
Is there a chance to achieve this information?
Thx in Advance
Chakoe
Yes, that is possible, but you will need to loop through all the harddisks.
As a consequence there will be a considerable amount of repeated information (everything you have now) in each row.
Is that what you want?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at this to see what I mean.
$vmreport = foreach($vm in Get-Cluster ClusterName | Get-VM){
foreach($hd in Get-HardDisk -VM $vm){
$hd | Select @{N="VMName";E={$vm.Name}},
@{N="VM-OSID";E={$vm.ExtensionData.Config.GuestID}},
@{N="VM-OS";E={$vm.ExtensionData.Config.GuestFullName}},
@{N="VM-Version";E={$vm.ExtensionData.Config.Version}},
@{N="VM-CPUs";E={$vm.ExtensionData.Config.Hardware.NumCpu}},
@{N="VM-CPU-Sockets";E={$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM-Memory(MB)";E={$vm.ExtensionData.Config.Hardware.MemoryMB}},
@{N="VM-Datastore";E={$vm.ExtensionData.Config.DatastoreUrl.Name}},
@{N="VM-NIC-Networkname";E={$vm.ExtensionData.Guest.Net.Network}},
@{N="VM-NIC-MAC-Adress";E={$vm.ExtensionData.Guest.Net.MacAddress}},
@{N="VM-NIC-IP-Adress";E={$vm.ExtensionData.Guest.Net.IPAddress}},
@{N="VM-Annotation";E={$vm.ExtensionData.Config.Annotation}},
@{N='VM-HD-Count';E={($vm.ExtensionData.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualDisk]}).Count}},
@{N='VM-HD-Name';E={$hd.Name}},
@{N='VM-HD-Size(GB)';E={$hd.CapacityGB}},
@{N='VM-HD-Path';E={$hd.FileName}},
@{N='VM-HD-Type';E={$hd.DiskType}},
@{N='VM-HD-Canonical';E={
$hd.Parent.VMHost.ExtensionData.Config.StorageDevice.ScsiLun |
where{$_.Uuid -eq $hd.ExtensionData.Backing.LunUuid} |
select -ExpandProperty CanonicalName
}}
}
}
$vmreport | Out-Gridview
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
works great for me, thank you !! but....is it possible to do the same , if a VM has more than one NIC ? Do we need an extra Loop ?
That is possible, but how are you going to combine multiple harddisks with multiple vNICs?
If you have 2 of each, that would already result in 4 rows, with a lot of redundant information in there.
Wouldn't it be more efficient to have two separate reports, each for example in a separate worksheet in the same Excel file?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This would also be a good idea...but...for me it´s important to have the Infos, the Format or visibilty is second-rated 😉 If the Output results in multiple line´s per VM, then i would be able to filter in Excel 😉
What if we join the info like this?
You will see all the info, but the number of rows stays limited.
$vmreport = foreach($vm in Get-Cluster ClusterName | Get-VM){
foreach($hd in Get-HardDisk -VM $vm){
$hd | Select @{N="VMName";E={$vm.Name}},
@{N="VM-OSID";E={$vm.ExtensionData.Config.GuestID}},
@{N="VM-OS";E={$vm.ExtensionData.Config.GuestFullName}},
@{N="VM-Version";E={$vm.ExtensionData.Config.Version}},
@{N="VM-CPUs";E={$vm.ExtensionData.Config.Hardware.NumCpu}},
@{N="VM-CPU-Sockets";E={$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM-Memory(MB)";E={$vm.ExtensionData.Config.Hardware.MemoryMB}},
@{N="VM-Datastore";E={$vm.ExtensionData.Config.DatastoreUrl.Name}},
@{N="VM-NIC-Networkname";E={$vm.ExtensionData.Guest.Net.Network -join ' | '}},
@{N="VM-NIC-MAC-Adress";E={$vm.ExtensionData.Guest.Net.MacAddress -join ' | '}},
@{N="VM-NIC-IP-Adress";E={$vm.ExtensionData.Guest.Net.IPAddress -join ' | '}},
@{N="VM-Annotation";E={$vm.ExtensionData.Config.Annotation}},
@{N='VM-HD-Count';E={($vm.ExtensionData.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualDisk]}).Count}},
@{N='VM-HD-Name';E={$hd.Name}},
@{N='VM-HD-Size(GB)';E={$hd.CapacityGB}},
@{N='VM-HD-Path';E={$hd.FileName}},
@{N='VM-HD-Type';E={$hd.DiskType}},
@{N='VM-HD-Canonical';E={
$hd.Parent.VMHost.ExtensionData.Config.StorageDevice.ScsiLun |
where{$_.Uuid -eq $hd.ExtensionData.Backing.LunUuid} |
select -ExpandProperty CanonicalName
}}
}
}
$vmreport | Out-Gridview
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Looks very very nice for me , thanks a lot !!!
I added an $vmreport | Export-Excel $outputfile -Show -Autosize -FreezeTopRow -Autofilter at the End of the Script
Is there any Information about the VMs you would add to the Script?
For example: If i would use the Script-output to rebuild broken or lost VMs ( Create empty VM with identical Sizing and - if needed - RawDeviceMappings ) ?
ScsiController-Type? SCSI-ID of RDM ?
Wherever your selection diverts from the defaults, those values would need to be in a list to recreate the VMs.
And yes, the SCSI controller type would be such a value.
There are potentially others, like for example the video card configuration (if not default), the CPU and memory reservations (if those are used)...
As you can see, depends on what exactly you change on your VMs, and what is not the default.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference