VMware Cloud Community
mars0077
Enthusiast
Enthusiast
Jump to solution

VM Creation Report

Hi guys,

I need some help in completing a VM creation report I am working on. All I need to do is be able to add some additional fields to the output but can't seem to get that to work. 

Below is the code that I am using and it is limited since I can only include Created time, Username, FullFormattedMessage, CPU, MemoryGB, HardwareVersion, Folder and VMhost. I would like to also include ESX cluster, VM IP address and Datastore.

CODE:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-7) | where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent" -or $_.Gettype().Name-eq "VmRegisteredEvent"} | Sort CreatedTime -Descending | Select CreatedTime, UserName,FullformattedMessage, @{ Name="CPU"; Expression={(Get-VM -Name $_.Vm.Name).NumCPU}}, @{ Name="MemoryGB"; Expression={(Get-VM -Name $_.Vm.Name).MemoryGB}}, @{ Name="HardwareVersion"; Expression={(Get-VM -Name $_.Vm.Name).HardwareVersion}}, @{ Name="Folder"; Expression={(Get-VM -Name $_.Vm.Name).Folder}}, @{ Name="VMHost"; Expression={(Get-VM -Name $_.Vm.Name).VMHost}}

If possible I would like report to look like the example below.

VM NameClusterVMhostVM IPAddressFolderDatastoreCreated TimeUsernameHardwareVersionNumCPUMemoryGB

ProvisionedSpaceGB

 

Any help here is greatly appreciated!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can add additional calculated properties for that

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-7) | 
where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent" -or $_.Gettype().Name-eq "VmRegisteredEvent"} | 
Sort CreatedTime -Descending | 
Select CreatedTime, UserName,FullformattedMessage, 
    @{ Name="CPU"; Expression={(Get-VM -Name $_.Vm.Name).NumCPU}}, 
    @{ Name="MemoryGB"; Expression={(Get-VM -Name $_.Vm.Name).MemoryGB}}, 
    @{ Name="HardwareVersion"; Expression={(Get-VM -Name $_.Vm.Name).HardwareVersion}}, 
    @{ Name="Folder"; Expression={(Get-VM -Name $_.Vm.Name).Folder}}, 
    @{ Name="VMHost"; Expression={(Get-VM -Name $_.Vm.Name).VMHost}},
    @{N='Datastore';E={(Get-VM -Name $_.VM.Name | Get-Datastore).Name -join '|'}},
    @{N='Cluster';E={(Get-Cluster -VM $_.VM.Name).Name}},
    @{N='IPAddr';E={(Get-VM -Name $_.VM.Name).Guest.IPAddress -join '|'}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

You can add additional calculated properties for that

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-7) | 
where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent" -or $_.Gettype().Name-eq "VmRegisteredEvent"} | 
Sort CreatedTime -Descending | 
Select CreatedTime, UserName,FullformattedMessage, 
    @{ Name="CPU"; Expression={(Get-VM -Name $_.Vm.Name).NumCPU}}, 
    @{ Name="MemoryGB"; Expression={(Get-VM -Name $_.Vm.Name).MemoryGB}}, 
    @{ Name="HardwareVersion"; Expression={(Get-VM -Name $_.Vm.Name).HardwareVersion}}, 
    @{ Name="Folder"; Expression={(Get-VM -Name $_.Vm.Name).Folder}}, 
    @{ Name="VMHost"; Expression={(Get-VM -Name $_.Vm.Name).VMHost}},
    @{N='Datastore';E={(Get-VM -Name $_.VM.Name | Get-Datastore).Name -join '|'}},
    @{N='Cluster';E={(Get-Cluster -VM $_.VM.Name).Name}},
    @{N='IPAddr';E={(Get-VM -Name $_.VM.Name).Guest.IPAddress -join '|'}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mars0077
Enthusiast
Enthusiast
Jump to solution

Thanks for your help LucD! This was all I needed!

Reply
0 Kudos