I'm running a report to view virtual machines created during a specified time period. I'm able to view everything in the report except the memory size of the VM.
Here is the simplified version of the report. Any ideas what is wrong?
Get-VIEvent -maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-33) |
where {"VmCreatedEvent" -contains $_.Gettype().Name} |
Select createdTime, userName,@{N="VM";E={$_.VM.Name}},@{N="RAM";E={$_.VM.MemoryGB}}
Everything works except memoryGB
I'm guessing the issue here is that even though the event contains the name of the virtual machine, It doesn't contain the actual memory configuration of the virtual machine. Perhaps I need to query vcenter server for the current memory configuration of the VM as an alternative, including a try / catch statement in case the VM is no longer in vCenter so that my report doesn't error out?
Hi,
Try the following:
Get-VIEvent -maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-33) | Where-Object {$_.ConfigSpec -and $_.FullFormattedMessage -match "Creating"} | Select CreatedTime, UserName, @{N="VM";E={$_.ConfigSpec.Name}}, @{N="RAM";E={$_.ConfigSpec.MemoryMB}}
I get the same result attempting that - the memory column is blank for the @{N="RAM";E={$_.ConfigSpec.MemoryMB}} property.
I guess the question goes back to this:
The question is: is every aspect of a virtual machine's configuration really captured in that event object? RAM, CPU, memory size, disk size, etc.? If so, then just by pulling that event object, I have all the information normally returned in a virtual machine object - the same as if I ran "Get-vm vm1". If not, then you have to try something different to get that info. I'm trying to view these events in a property inspector to see what properties are actually there but I'm unable to for some reason.
That's strange, the command shows me the RAM information:
CreatedTime : 6/12/2013 10:07:38 a.m.
UserName : test
VM : asdf
RAM : 4096
The ConfigSpec property has the followings:
ChangeVersion :
Name : asdf
Version : vmx-10
Uuid : 423ca4b0-2947-80df-bff2-68c50e66c229
InstanceUuid : 503cdb51-08a4-24dd-d94d-b2675b53acd7
NpivNodeWorldWideName :
NpivPortWorldWideName :
NpivWorldWideNameType :
NpivDesiredNodeWwns :
NpivDesiredPortWwns :
NpivTemporaryDisabled :
NpivOnNonRdmDisks :
NpivWorldWideNameOp :
LocationId :
GuestId : windows7Server64Guest
AlternateGuestName :
Annotation :
Files : VMware.Vim.VirtualMachineFileInfo
Tools : VMware.Vim.ToolsConfigInfo
Flags : VMware.Vim.VirtualMachineFlagInfo
ConsolePreferences :
PowerOpInfo : VMware.Vim.VirtualMachineDefaultPowerOpInfo
NumCPUs : 1
NumCoresPerSocket : 1
MemoryMB : 4096
MemoryHotAddEnabled :
CpuHotAddEnabled :
CpuHotRemoveEnabled :
VirtualICH7MPresent :
VirtualSMCPresent :
DeviceChange : {VMware.Vim.VirtualDeviceConfigSpec, VMware.Vim.VirtualDeviceConfigSpec, VMware.Vim.VirtualDeviceConfigSpec, VMware.Vim.VirtualDeviceConfigSpec...}
CpuAllocation : VMware.Vim.ResourceAllocationInfo
MemoryAllocation : VMware.Vim.ResourceAllocationInfo
LatencySensitivity :
CpuAffinity : VMware.Vim.VirtualMachineAffinityInfo
MemoryAffinity : VMware.Vim.VirtualMachineAffinityInfo
NetworkShaper :
CpuFeatureMask :
ExtraConfig :
SwapPlacement : inherit
BootOptions :
VAppConfig :
FtInfo :
VAppConfigRemoved :
VAssertsEnabled :
ChangeTrackingEnabled :
Firmware : bios
MaxMksConnections :
GuestAutoLockEnabled :
ManagedBy :
MemoryReservationLockedToMax :
NestedHVEnabled :
VPMCEnabled :
ScheduledHardwareUpgradeInfo :
VmProfile :
DynamicType :
DynamicProperty :