{"id":5100,"date":"2012-08-21T00:01:00","date_gmt":"2012-08-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/08\/21\/use-powershell-to-check-the-license-status-of-windows-8\/"},"modified":"2012-08-21T00:01:00","modified_gmt":"2012-08-21T00:01:00","slug":"use-powershell-to-check-the-license-status-of-windows-8","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-check-the-license-status-of-windows-8\/","title":{"rendered":"Use PowerShell to Check the License Status of Windows 8"},"content":{"rendered":"<p><b>Summary<\/b>: Use Windows PowerShell and WMI to determine the number of days remaining on an evaluation copy of Windows 8.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the cool features in Windows 8 is that it has Hyper-V built-in to it. This means that I can use the cool new Hyper-V cmdlets to manage things. For example, I can type the following command to start all of my virtual machines:<\/p>\n<p style=\"padding-left: 30px\">Get-VM | Start-VM<\/p>\n<p>When I am finished making my presentation, I can use the following command to shut down all of the virtual machines.<\/p>\n<p style=\"padding-left: 30px\">Get-VM | Stop-VM<\/p>\n<p>All this is pretty cool, until I get ready to make a presentation, and all of my virtual machines are whining that they need to activate or they will shut down. Not the best situation if you are preparing to make a presentation at something like TechEd or Tech Mentor. One way to ensure that this situation does not occur is to use the following script.<\/p>\n<p style=\"padding-left: 30px\">Get-WindowsLicensingStatus.ps1<\/p>\n<p style=\"padding-left: 30px\">$cim = New-CimSession -ComputerName (get-vm).name -Credential nwtraders\\administrator<\/p>\n<p style=\"padding-left: 30px\">get-ciminstance -class SoftwareLicensingProduct -CimSession $cim |<\/p>\n<p style=\"padding-left: 30px\">&nbsp; where {$_.name -match &#8216;windows&#8217; -AND $_.licensefamily} |<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; format-list -property Name, Description, `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @{Label=&#8221;Grace period (days)&#8221;; Expression={ $_.graceperiodremaining \/ 1440}}, `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @{Label= &#8220;License Status&#8221;; Expression={switch (foreach {$_.LicenseStatus}) `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 0 {&#8220;Unlicensed&#8221;} `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 {&#8220;Licensed&#8221;} `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 {&#8220;Out-Of-Box Grace Period&#8221;} `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 {&#8220;Out-Of-Tolerance Grace Period&#8221;} `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 {&#8220;Non-Genuine Grace Period&#8221;} `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } } }<\/p>\n<p>The first thing I do is create a CIM session to connect to all of my virtual machines. I use the cool automatic foreach technique that I talked about yesterday in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/08\/20\/my-five-favorite-powershell-3-0-tips-and-tricks.aspx\" target=\"_blank\">My Five Favorite PowerShell 3.0 Tips and Tricks<\/a>. Now, I use the <b>Get-CimInstance<\/b> cmdlet to perform a WMI query on each of the servers and clients that are running on my virtual machine.<\/p>\n<p style=\"padding-left: 30px\"><b>Note&nbsp;&nbsp;&nbsp;<\/b>I could have used the <b>Get-VM | Start-VM<\/b> commands that I mentioned at the beginning of this blog post to start the virtual machines and to check their status.<\/p>\n<p>I filter out the software products by names that match <b>Windows<\/b><i> <\/i>and only those elements that have a <b>LicenseFamily<\/b><i>. <\/i>Then I pipe the results to the <b>Format-List<\/b> cmdlet to produce a nice output. Keep in mind, if I am running this against a larger network, I might want to export the information to a CSV file so I can easily sort the results in Microsoft Excel.<\/p>\n<p>The command itself uses a couple of custom labels: the <b>GracePeriodRemaining <\/b>property reports in minutes; therefore, to have a more meaningful result, I divide by 1440. The <b>LicenseStatus<\/b> property reports as an enumeration, so I use a <b>switch<\/b> statement to create a more easily readable report. Certain builds report multiple items. As shown in the image that follows, the server reports multiple items, all of which say there are no remaining grace days and no licensing status.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5584.HSG-8-21-12-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5584.HSG-8-21-12-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>When I run the script (modified slightly) against my local computer, however, it reports exactly how much grace time I have, and the license status.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3872.HSG-8-21-12-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3872.HSG-8-21-12-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>This WMI class also reports on things like Office status. Therefore, if you are running the beta version of Office 15 (like I am doing), that product also reports&mdash;all I need to do is change my <b>Where-Object<\/b>. This results in the command shown here.<\/p>\n<p style=\"padding-left: 30px\">get-ciminstance -class SoftwareLicensingProduct |<\/p>\n<p style=\"padding-left: 30px\">&nbsp; where {$_.name -match &#8216;office&#8217; -AND $_.licensefamily}<\/p>\n<p>The output of the command is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7041.HSG-8-21-12-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7041.HSG-8-21-12-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>That is about all there is to examining licensing activation status for Windows&nbsp;8 or for Windows Server&nbsp;2012. Join me tomorrow for more cool Windows PowerShell stuff.<\/p>\n<p>I 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=\"mailto: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.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use Windows PowerShell and WMI to determine the number of days remaining on an evaluation copy of Windows 8. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool features in Windows 8 is that it has Hyper-V built-in to it. This means that I can use the cool new Hyper-V cmdlets to [&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":[365,31,3,45,366],"class_list":["post-5100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-activation","tag-operating-system","tag-scripting-guy","tag-windows-powershell","tag-windows-powershell-3-0"],"acf":[],"blog_post_summary":"<p>Summary: Use Windows PowerShell and WMI to determine the number of days remaining on an evaluation copy of Windows 8. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool features in Windows 8 is that it has Hyper-V built-in to it. This means that I can use the cool new Hyper-V cmdlets to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5100","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=5100"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5100\/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=5100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=5100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=5100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}