{"id":4238,"date":"2013-01-29T00:01:00","date_gmt":"2013-01-29T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/01\/29\/use-powershell-to-reset-hyper-v-resource-metering\/"},"modified":"2013-01-29T00:01:00","modified_gmt":"2013-01-29T00:01:00","slug":"use-powershell-to-reset-hyper-v-resource-metering","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-reset-hyper-v-resource-metering\/","title":{"rendered":"Use PowerShell to Reset Hyper-V Resource Metering"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary:<\/strong><span style=\"font-size: 12px\"> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 to reset Hyper-V Resource Metering.<\/span>\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Hey, Scripting Guy! Ok, I have this problem here at work. We have upgraded our servers running Windows Server&nbsp;2008&nbsp;R2 to Windows Server&nbsp;2012. We are running Hyper-V, and we need to get a resource report each month to cross-charge other departments for the computing resources they use. Here is the problem. I read your article last week about resource metering, and I told my boss I had found the problem. He immediately said, &ldquo;Well that may work this month, but what about next month.&rdquo; I stood there looking like a deer in the headlights while he explained, &ldquo;If we tell a department they use xyz resources this month, how do we get a fresh number for next month? Are we supposed to keep adding and subtracting and all that to come up with new numbers?&rdquo; Please help me. I am the one who told my boss that I thought we could do what we need to do by using Windows Server&nbsp;2012 and that we did not need to buy a new product to manage our resources. You see, my boss is like a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wookiee\" target=\"_blank\">wookiee<\/a>, and <a href=\"https:\/\/www.youtube.com\/watch?v=mO6M4ngKRp0\" target=\"_blank\">I don&rsquo;t want to make him mad<\/a>.\n&mdash;JJ\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Hello JJ,\nMicrosoft Scripting Guy, Ed Wilson, is here. Well, this morning things are cool. In fact, the entire house is a bit cool because outside it is freezing. I know, I live in the Deep South, and I should not complain about cold, because our cold is really quite warm, when compared to places like Nome, Alaska. But, hey, to me it feels cold.\nAnyway, I am up this morning because I am making an &ldquo;Industry Leadership&rdquo; live meeting with a group of Microsoft PFEs in the UK. I am talking about the things I did to help to raise my profile in the community. It is kind of cool, and I am glad to help out. (I am also honored to be invited to speak to this group of way-cool and talented people.)\nAnyway, JJ, you do not need to worry about upsetting your wookiee manager. In fact, after today&rsquo;s article, you will need to worry about escaping a wookiee hug instead.<\/p>\n<p style=\"padding-left: 30px\"><strong>Exam note<\/strong> &nbsp;&nbsp;One of the objectives on the <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/exam.aspx?ID=70-410\" target=\"_blank\">Exam 70-410: Installing and Configuring Windows Server 2012<\/a><em> <\/em>is <em>configure Resource Metering, <\/em>and so if you are working on your new <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/mcse-server-infrastructure-certification.aspx\" target=\"_blank\">MCSE for <em>Server Infrastructure<\/em><\/a>, you will want to know this material. Of course, if you are running or thinking about running Hyper-V on Windows Server&nbsp;2012, you will want to know this information as well. The <a href=\"http:\/\/blogs.technet.com\/b\/virtualization\/archive\/2012\/08\/16\/introduction-to-resource-metering.aspx\" target=\"_blank\">Introduction to Resource Metering<\/a><em> <\/em>blog post written by Lalithra Fernando on the Virtualization Blog is an excellent place to start. Lalithra also wrote a blog post called <a href=\"http:\/\/blogs.technet.com\/b\/virtualization\/archive\/2012\/08\/20\/how-to-use-resource-metering-with-powershell.aspx?Redirected=true\" target=\"_blank\">How to Use Resource Metering with PowerShell<\/a><em>, <\/em>which is also a good introduction.<\/p>\n<h2>Use PowerShell to see how long Resource Metering runs<\/h2>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong> &nbsp;&nbsp;This is the third article in a series about Hyper-V and Windows PowerShell. In the first article, I talked about using <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/01\/27\/weekend-scripter-use-powershell-to-meter-resources-on-hyper-v-windows-server-2012.aspx\" target=\"_blank\">PowerShell to Meter Resources on Hyper-V Windows Server 2012<\/a>. In the second article, I discussed <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/01\/28\/use-powershell-to-configure-hyper-v-resource-metering.aspx\" target=\"_blank\">using PowerShell to Configure Hyper-V Resource Metering<\/a>. This article is also the fifth post <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/mcse\/\" target=\"_blank\">in a series I have written about the MCSE exam 70-410<\/a>.\nResetting Hyper-V Resource Meter counters is actually pretty easy&mdash;after all, there is a dedicated Windows PowerShell cmdlet to use to accomplish the task. If you need to do this on a monthly basis, use the Task Scheduler to create a task to run the cmdlet. Set it for 1 minute after midnight on the first day of the month&mdash;if that is your billing cycle&mdash;and you are good to go.\nTo see how long it has been since the Resource Metering counters have been reset, I use the <strong>Get-VM<\/strong> cmdlet to return a <strong>VirtualMachine<\/strong> object, and I pipe the object to the <strong>Measure-VM<\/strong> cmdlet. I then select the <strong>MeteringDuration<\/strong> property. The command below illustrates this technique.<\/p>\n<p style=\"padding-left: 30px\">10:24 C:&gt; get-vm -VMName c1 | measure-vm | select meter*<\/p>\n<p style=\"padding-left: 30px\">MeteringDuration<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">00:31:33.8220000\nIf I want a report for all of my virtual machines, I only need to change the <strong>VMName<\/strong> property value to a wildcard. Once I do this, I decide I need to add the <strong>VMName<\/strong> property to the output. The revised command is shown here.<\/p>\n<p style=\"padding-left: 30px\">10:40 C:&gt; get-vm -VMName * | measure-vm | select vmname, meter*<\/p>\n<p style=\"padding-left: 30px\">VMName&nbsp;&nbsp;&nbsp;&nb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style=\"padding-left: 30px\">C2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.19:02:25.6450000<\/p>\n<p style=\"padding-left: 30px\">c1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:33:02.7300000<\/p>\n<h2>Reset the Resource Metering counters<\/h2>\n<p>To reset the Resource Metering counters for a single virtual machine I use the <strong>Get-VM<\/strong> cmdlet and specify a single computer name. I pipe the resulting <strong>VirtualMachine<\/strong> object to the <strong>Reset-VMResourceMetering<\/strong> cmdlet. This command is shown here.<\/p>\n<p style=\"padding-left: 30px\">get-vm -VMName c1 | Reset-VMResourceMetering\nNothing returns from running the previous command, so I use the <strong>Get-VM<\/strong> cmdlet to return a <strong>VirtualMachine<\/strong> object, and I pipe it to the <strong>Measure-VM<\/strong> cmdlet to obtain the Resource Metering report for the virtual machine. I then select the <strong>MeteringDuration<\/strong> property to see if the counter has been reset. This command is shown here, and it tells me that the counters were reset 24 seconds ago.<\/p>\n<p style=\"padding-left: 30px\">10:42 C:&gt; get-vm -VMName c1 | measure-vm | select meter*<\/p>\n<p style=\"padding-left: 30px\">MeteringDuration<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">00:00:24.8590000\nTo reset the Resource Metering counters for all virtual machines on the host I use a wildcard to obtain all virtual machines on the local computer. I pipe the returned <strong>VirtualMachine<\/strong> objects to the <strong>Reset-VMResourceMetering<\/strong> cmdlet. The command is shown here.<\/p>\n<p style=\"padding-left: 30px\">get-vm -VMName * | Reset-VMResourceMetering\nAs before, nothing returns from running the <strong>Reset-VMResourceMetering<\/strong> cmdlet. To verify the changes took effect, I use the UP arrow and retrieve my previous Get-VM | Measure-VM | Select Meter* command. This time, I add the <strong>VMName<\/strong> to the output so I can see both virtual machine name as well as the metering duration.<\/p>\n<p style=\"padding-left: 30px\">10:43 C:&gt; get-vm -VMName * | measure-vm | select vmname, meter*<\/p>\n<p style=\"padding-left: 30px\">&nbsp;VMName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MeteringDuration<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">sql1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00:00:06.4740000<\/p>\n<p style=\"padding-left: 30px\">DC1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:07.0280000<\/p>\n<p style=\"padding-left: 30px\">C2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:07.3940000<\/p>\n<p style=\"padding-left: 30px\">c1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:07.6050000\nJJ, that is all there is to using Windows PowerShell to reset Hyper-V Resource Metering counters. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 to reset Hyper-V Resource Metering. &nbsp;Hey, Scripting Guy! Ok, I have this problem here at work. We have upgraded our servers running Windows Server&nbsp;2008&nbsp;R2 to Windows Server&nbsp;2012. We are running Hyper-V, and we need to get a resource report each month to cross-charge other [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[271,402,362,3,367,45,368],"class_list":["post-4238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-hyper-v","tag-mcse","tag-powershell-3","tag-scripting-guy","tag-windows-8","tag-windows-powershell","tag-windows-server-2012"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 to reset Hyper-V Resource Metering. &nbsp;Hey, Scripting Guy! Ok, I have this problem here at work. We have upgraded our servers running Windows Server&nbsp;2008&nbsp;R2 to Windows Server&nbsp;2012. We are running Hyper-V, and we need to get a resource report each month to cross-charge other [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4238"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4238\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}