#PSTip Automatic refresh of Hyper-V VM Objects

Note: This tip requires PowerShell 3.0 or above.

When using the Hyper-V PowerShell cmdlets in Windows Server 2012, the VM objects can be retrieved using Get-VM cmdlet.

$vm = Get-VM

By default, these VM objects refresh based on the events from the virtual machines. For example, take a look at this screen capture:

vm

As you see, the VM object in $vm gets refreshed automatically. This is possible because, by default, virtual machine eventing is enabled. We can disable this behavior by using Disable-VMEventing cmdlet. This might be useful in cases when we want to use the VM object in a script, work on the VM’s captured object state and not refresh the object.

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts

%d bloggers like this: