<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M SarmientoQuery Hyper-V Virtual machines using Windows PowerShell &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>Query Hyper-V Virtual machines using Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/#respond</comments>
		<pubDate>Tue, 16 Feb 2010 23:19:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2010/02/16/query-hyper-v-virtual-machines-using-windows-powershell</guid>

				<description><![CDATA[Being a lazy administrator as I am, I try to minimize the amount of mouse-clicks I need to make to retrieve information about something on a Windows platform. As I have been using Microsoft Hyper-V on a bunch of my test machines, I always check if a VM is up and running before I power [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">Being a lazy administrator as I am, I try to minimize the amount of mouse-clicks I need to make to retrieve information about something on a Windows platform. As I have been using Microsoft Hyper-V on a bunch of my test machines, I always check if a VM is up and running before I power down my host machine (imagine the amount of electricity consumed just by keeping your machine up and running even without using it). This is specifically the case when dealing with my Windows XP VMs. I noticed that the profiles get corrupted if I shutdown the host machine without properly shutting down the VM. So, I always made sure that the VMs are not running before powering down the host machine.</span></p>
<p><span style="font-family:arial;">I wrote a PowerShell command to query the current state of the VMs running on Hyper-V</span></p>
<pre class="brush: powershell; title: ; notranslate">
Get-WMIObject -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot;
</pre>
<p><span style="font-size:85%;"><span style="font-family:arial;">This will actually display a bunch of information about the VMs running on Hyper-V but what we&#8217;re really concerned about is the name of the VM and it&#8217;s currently running state. These two properties are associated with the ElementName and EnabledState attributes of the </span><a href="http://msdn.microsoft.com/en-us/library/cc136822(VS.85).aspx"><span style="font-family:arial;">MSVM_ComputerSystem</span></a><span style="font-family:arial;"> class. All we need to do with the command above is to pipe the results to a <a href="http://technet.microsoft.com/en-us/library/dd315291.aspx">Select-Object</a> cmdlet, specifying only these two properties, as follows</span></span></p>
<pre class="brush: powershell; title: ; notranslate">
Get-WMIObject -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot; | Select-Object ElementName, EnabledState
</pre>
<p><span style="font-family:arial;"> While the <strong>EnabledState</strong> property will give you a bunch of numbers, I&#8217;m only concerned with those values equal to 2, which means that the VM is running. But, then, you might not remember what the value 2 means. So might as well write an entire script that checks for the value of the <strong>EnabledState</strong> property. I&#8217;ve used the GWMI alias to call the <strong>Get-WMIObject</strong> cmdlet</span></p>
<pre class="brush: powershell; title: ; notranslate">
$VMs = gwmi -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot;
foreach ($VM IN $VMs)
{
switch ($VM.EnabledState)
{
2{$state=&amp;quot;Running&amp;quot; }
3{$state=&amp;quot;Stopped&amp;quot; }
32768{$state=&amp;quot;Paused&amp;quot; }
32769{$state=&amp;quot;Suspended&amp;quot; }
32770 {$state=&amp;quot;Starting&amp;quot; }
32771{$state=&amp;quot;Taking Snapshot&amp;quot; }
32773{$state=&amp;quot;Saving&amp;quot; }
32774{$state=&amp;quot;Stopping&amp;quot; }
}
write-host $VM.ElementName `,` $state
}

</pre>
<p><span style="font-family:arial;">On a side note, make sure you are running as Administrator when working with this script as you will only see the VMs that your currently logged in profile has permission to access. Running as Administrator will show you all of the VMs configured on your Hyper-V server</span></p>
<div class="blogger-post-footer"></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">208</post-id>	</item>
	</channel>
</rss>