Begin {
Collection of property names for custom object
$PropertyCol = @(
"Name", "OS", "Host", "CPU (Count)", "Memory (MB)",
"VM Extent", "Datastore Name"
)
}
Process {
if ( $_ -isnot http://VMware.VimAutomation.Client20.VirtualMachineImpl ) { continue }
$process = "" | Select-Object -Property $PropertyCol
$process.Name = $_.Name
$process.OS = $_.Guest.OSFullName
$process.Host = $_.Host.Name
$process."CPU (Count)" = $_.NumCpu
$process."Memory (MB)" = $_.MemoryMB
$process."VM Extent" = $_ | get-datastore | get-view | %{ $_.Info.Vmfs.Extent }
$process."Datastore Name" = $_ | get-datastore | Select Name
Write-Output $process
}
The problem I'm having is in the output:
Name : MyVM
OS : Microsoft Windows Server 2003, Standard Edition (32-bit)
Host : esx.domain.com
CPU (Count) : 1
Memory (MB) : 4096
VM Extent : VMware.Vim.HostScsiDiskPartition
Datastore Name : @{Name=SomeName}
I need to expand out VM Extent & Datastore name. Thoughts?
-Cody Bunch
vExpert, VCP VI3
For multiple items, this works (bit I dont like it) someone else may find a nicer way.
Foreach ($Extent in ($_ | get-datastore | get-view | %{ $_.Info.Vmfs.Extent })){ $process."VM Extent" += " $($Extent.DiskName)" } Foreach ($Datastorename in ($_ | get-datastore | Select Name)){ $Process."Datastore Name" += " $($Datastorename.Name)" }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
Is this what you want ?
$process."VM Extent" = ($_ | get-datastore | get-view | %{ $_.Info.Vmfs.Extent }).DiskName $process."Datastore Name" = ($_ | get-datastore | Select Name).Name
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
For multiple items, this works (bit I dont like it) someone else may find a nicer way.
Foreach ($Extent in ($_ | get-datastore | get-view | %{ $_.Info.Vmfs.Extent })){ $process."VM Extent" += " $($Extent.DiskName)" } Foreach ($Datastorename in ($_ | get-datastore | Select Name)){ $Process."Datastore Name" += " $($Datastorename.Name)" }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
V1
Filter VMQuickReport { Where-Object -InputObject $_ -FilterScript {$_.gettype().name -eq "VirtualMachineImpl"} | Select-Object Name, NumCpu, MemoryMB, @{ Name='OS' Expression={$_.Guest.OSFullName} }, @{ Name='Host' Expression={$_.Host.Name} }, @{ Name='Extent' Expression={ Get-Datastore -VM $_ | Get-View -Property info |%{ $_.Info.VMfs.Extent|%{ $_.DiskName } } } }, @{ Name='Datastore' Expression={ Get-Datastore -VM $_|%{ $_.name } } } }
V2
Function Get-VMReport { [CmdletBinding()] Param( [parameter(Mandatory=$true,ValueFromPipeline=$true)] \[VMware.VimAutomation.Client20.VirtualMachineImpl] $VM ) #called up front to avoid multiple calls $DataStore = Get-Datastore -VM $VM Write-Output $VM | Select-object Name, NumCpu, MemoryMB, @{ Name='OS' Expression={$_.Guest.OSFullName} }, @{ Name='Host' Expression={$_.Host.Name} }, @{ Name='Datastore' Expression={$DataStore.Name} }, @{ Name='Extent' Expression={ $datastore | Get-View -Property Info | Select-Object -ExpandProperty Info | Where-Object {$_.VMFS} | Select-Object -ExpandProperty VMFS | Select-Object -ExpandProperty Extent | Select-Object -ExpandProperty DiskName } } }
The V2 advanced function is about 50% faster. This is due to both the use of Select-Object -Expand vs nested Foreach-object loops. We also get a nice boost by offloading all parameter validation.
Perhaps not exactly what you were looking for, but I prefer to build stuff I can use from the cmdline.
~Glenn