{"id":17261,"date":"2010-08-31T00:01:00","date_gmt":"2010-08-31T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/08\/31\/get-windows-power-plan-settings-on-your-computer-by-using-powershell\/"},"modified":"2010-08-31T00:01:00","modified_gmt":"2010-08-31T00:01:00","slug":"get-windows-power-plan-settings-on-your-computer-by-using-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/get-windows-power-plan-settings-on-your-computer-by-using-powershell\/","title":{"rendered":"Get Windows Power Plan Settings on Your Computer by Using PowerShell"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong>: Use Windows PowerShell to retrieve the power plan settings for your computer. The Microsoft Scripting Guys show you how.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8461.clip_image0015_1D36E8DA.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image001[5]\" border=\"0\" alt=\"clip_image001[5]\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6646.clip_image0015_thumb_078C8A70.jpg\" width=\"34\" height=\"34\" \/><\/a>Hey, Scripting Guy! I need to have a way to easily retrieve the power plan settings for the active power plan on my computer. I would like to have an easy to read display of the setting name, the allowable values, and the current value for when the computer is on battery power and for when it is on AC power. I know this seems like a lot to ask, but can Windows PowerShell retrieve this information for me?<\/p>\n<p>&#8212; LC<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3603.clip_image0025_0DD360FE.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image002[5]\" border=\"0\" alt=\"clip_image002[5]\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2438.clip_image0025_thumb_1F43C1D6.jpg\" width=\"34\" height=\"34\" \/><\/a>Hello LC, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. Today is Friday; at least it is if you live in Charlotte, <a href=\"http:\/\/en.wikipedia.org\/wiki\/North_Carolina\">North Carolina<\/a>, and you are a Scripting Guy who is working on next week&rsquo;s Hey, Scripting Guy! Blog posts. Better than the fact that it is Friday, it is actually Friday afternoon and as soon as this article is completed, I plan on securing for the day. Not that I will turn off my computer, or even that I will log out of the Redmond domain at work, but my writing mode will shut down and my play mode will kick in. I have a really complex <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394582(VS.85).aspx\">WMI<\/a> script I have been knocking around for the last two days, and I want to dig into it and figure out why it is not providing me the information I desire. As far as I can tell, no one has ever written a WMI script to do what I am working on, including the product group that wrote the WMI class I am messing around with. I did get a 1,500-line VBScript from one of the test engineers to exercise the class, but <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dude\">dude<\/a>! I was hoping for something a bit clearer. I am going to fire up the WMI administrative tools, and dig into the various class associations to see if I can figure out the relationships. I am really looking forward to it.<\/p>\n<p>Anyway, LC, I figure you are not interested in a 1,500-line VBScript, or even a 200-line Windows PowerShell script. So here you go&#8211;four lines of code. Admittedly, some it is a bit compact, but I will spend the next 2,000 words explaining it. The complete Get-ActivePowerPlanSettingsPwrCfg.ps1 script is shown here. <\/p>\n<blockquote>\n<p><strong>Get-ActivePowerPlanSettingsPwrCfg.ps1<\/strong><\/p>\n<p><span style=\"color: #2b91af\">$plan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Filter<\/span><span style=\"color: #808080\"> &#8220;isActive=&#8217;true'&#8221;&nbsp; <br \/><\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[regex]<\/span><span style=\"color: #808080\">&#8220;{(.*?)}$&#8221; <br \/><\/span><span style=\"color: #2b91af\">$planGuid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$plan<\/span><span style=\"color: #000000\">.instanceID.Tostring()).groups[<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">].value<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">powercfg<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-query<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$planGuid<\/span> <\/p>\n<\/blockquote>\n<p>I love using WMI to make command-line utilities more manageable. The PowerCfg.exe utility is a cool tool for interactively exploring and manipulating the power settings. One problem is the plethora of switches and the fact it relies on the power plan GUID for many operations. This means retrieving the GUID for the present power plan, and either copying it to the clipboard (assuming your current console has copy\/paste enabled) or doing a lot of writing and typing. Or performing impressive memory feats.<\/p>\n<p>In the Get-ActivePowerPlanSettingsPwrCfg.ps1 script, I basically &ldquo;cheat.&rdquo; I use WMI to retrieve the current power plan, use regular expressions to retrieve the GUID for the active power plan, and then pass the GUID for the active power plan to the powercfg.exe utility and tell it to retrieve the settings for the plan. There are essentially three steps:&nbsp;<\/p>\n<ol>\n<li>\n<p>WMI query <\/p>\n<\/li>\n<li>\n<p>Regular expression to parse the GUID <\/p>\n<\/li>\n<li>\n<p>Call to the Powercfg executable with the appropriate parameters and arguments <\/p>\n<\/li>\n<\/ol>\n<p>The Get-ActivePowerPlanSettingsPwrCfg.ps1 script consists of four logical lines (the first line, the WMI query, is broken into two lines because of limitations of displaying long lines of code on the blog platform. The backtick character (<strong>`<\/strong>) in Windows PowerShell is the line continuation character. <\/p>\n<blockquote>\n<p>The query to the Win32_PowerPlan WMI class was discussed in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/08\/30\/find-active-power-plan-on-remote-servers-by-using-powershell.aspx\">yesterday&rsquo;s Hey, Scripting Guy! Blog post<\/a>. <\/p>\n<\/blockquote>\n<p>The information that will be stored in the <strong>$plan<\/strong> variable is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;<br \/><\/span><span style=\"color: #000000\">-Filter<\/span><span style=\"color: #808080\"> &#8220;is Active=&#8217;true'&#8221; <\/span><\/div>\n<p><span style=\"color: #808080\"><\/p>\n<div class=\"code\"><\/div>\n<div class=\"code\"><span style=\"color: #0000ff\"><\/span><\/div>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<p><\/span><span style=\"color: #000000\">__GENUS<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__CLASS<\/span><span style=\"color: #808080\">&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;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Win32_PowerPlan<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__SUPERCLASS<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">CIM_SettingData<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__DYNASTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">CIM_ManagedElement<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__RELPATH<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Win32_PowerPlan.InstanceID<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&#8220;Microsoft:PowerPlan\\\\{1bef50e5-557d- <br \/>4b3b-9b29-cdde74fcfd30}&#8221; <br \/><\/span><span style=\"color: #000000\">__PROPERTY_COUNT<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">7<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__DERIVATION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{CIM_SettingData,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">CIM_ManagedElement}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__SERVER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">MRED1<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">__PATH<\/span><span style=\"color: #808080\">&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; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">\\\\MRED1\\root\\cimv2\\power:Win32_PowerPlan.InstanceID<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&#8220;Microsoft:P <br \/>owerPlan\\\\{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}&#8221; <br \/><\/span><span style=\"color: #000000\">Caption<\/span><span style=\"color: #808080\">&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; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">ChangeableType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">ConfigurationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">ElementName<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">My<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Custom<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Plan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">InstanceID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Microsoft:PowerPlan\\{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">IsActive<\/span><span style=\"color: #808080\">&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;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\"><\/span><\/p><\/blockquote>\n<p>There are only three properties that display any kind of interesting information: <strong>elementname<\/strong>, <strong>instanceID<\/strong>, and <strong>IsActive<\/strong>. Of those three properties, the only one we need for the Get-ActivePowerPlanSettingsPwrCfg.ps1 script is the <strong>InstanceID<\/strong>. Unfortunately, the <strong>InstanceID<\/strong> that is used by WMI is different than the GUID that is used by the PowerCfg.exe utility. <\/p>\n<p>By comparing the results of a WMI Query that only returns the <strong>InstanceID<\/strong> with a list of power schemes retrieved by the PowerCfg utility, it becomes apparent that it is possible to manipulate the WMI data to retrieve the GUID. The output from WMI and from PowerCfg is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Filter<\/span><span style=\"color: #808080\"> &#8220;is <br \/>Active=&#8217;true'&#8221;<\/span><span style=\"color: #000000\">).InstanceID<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Microsoft:PowerPlan\\{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">powercfg<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-list<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<p><span style=\"color: #808080\"><\/p>\n<div class=\"code\"><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<p><\/span><span style=\"color: #000000\">Existing<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Schemes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(*<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Active)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scheme<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GUID:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fcfd30<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(My<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Custom<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Plan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scheme<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GUID:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">381b4222-f694-41f0-9685-ff5bb260df2e<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(Balanced)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scheme<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GUID:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(High<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">performance)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scheme<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GUID:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">a1841308-3541-4fab-bc81-f71556f20b4a<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(Power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">saver)<\/span><span style=\"color: #808080\"> <\/span><\/p><\/blockquote>\n<p>It would be possible to use string manipulation to retrieve the GUID from the WMI information. By using the <strong>IndexOf<\/strong> method from the <strong>system.string<\/strong> .NET Framework class, and the <strong>substring<\/strong> method from the same class, the location of the &ldquo;<strong>{<\/strong>&ldquo; and the &ldquo;<strong>}<\/strong>&rdquo; can be determined and the length of the characters determined. When the start position and the length are known, the <strong>substring<\/strong> method returns the GUID from the WMI <strong>InstanceID<\/strong>. This is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;`<br \/><\/span><span style=\"color: #000000\">-Fi<\/span><span style=\"color: #000000\">lter<\/span><span style=\"color: #808080\"> &#8220;isActive=&#8217;true'&#8221;<\/span><span style=\"color: #000000\">).InstanceID.tostring()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">.IndexOf(<\/span><span style=\"color: #808080\">&#8220;{&#8220;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">.IndexOf(<\/span><span style=\"color: #808080\">&#8220;}&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #800000\">57<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">.Substring(<\/span><span style=\"color: #800000\">21<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #800000\">36<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fcfd30<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<\/blockquote>\n<p>By the way, to figure out the length of the GUID, I did not count up the letters, numbers, and dashes. That is way too confusing. I used the <strong>Measure-Object <\/strong>cmdlet with the character parameter. The alias for the <strong>Measure-Object<\/strong> cmdlet is <strong>measure<\/strong>. Therefore, the command is shown here. (Windows PowerShell is smart enough to ignore the <strong>&ldquo;&rdquo;<\/strong> that are required to supply a string to the Windows PowerShell console. Therefore, the string actually has 36 characters in it. You do <em>not <\/em>have to subtract 2 from this number to use it with substring). <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\"> &#8220;1bef50e5-557d-4b3b-9b29-cdde74fcfd30&#8221; <\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">measure<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Character<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Lines<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Words<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Characters<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #800000\">36<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<\/blockquote>\n<p>Before Windows PowerShell came along, I used Notepad to do my counting for me. Notice the cursor position indicator in the lower right corner of the following image. The number states that it is on line 1 and column 37 in Notepad; therefore, you need to always subtract one from the column number indicated because it is telling you where the first blank space resides. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1817.HSG08311001_091C92C9.jpg\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"Image of cursor position indicator in Notepad\" border=\"0\" alt=\"Image of cursor position indicator in Notepad\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2061.HSG08311001_thumb_08442CDF.jpg\" width=\"504\" height=\"166\" \/><\/a> <\/p>\n<p>The hardest part about using regular expressions is figuring out the pattern. We have several good Hey, Scripting Guy! Blog posts that talk about using <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/regular+expressions\/\">regular expressions<\/a> with VBScript as well as with Windows PowerShell. The <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/vbscript\/regular+expressions\/\">VBScript regular expression articles<\/a> are useful for Windows PowerShell scripters because they include information about the regular expression pattern. By the same token, the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/regular+expressions\/\">Windows PowerShell regular expression articles<\/a> are of use to VBScript scripters. <\/p>\n<p>The regular expression pattern that is used here is composed of eight characters that make up six different commands. The characters in the <strong>regex<\/strong> pattern are shown in Table 1.<\/p>\n<p><strong>Table 1<\/strong> <\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p><strong>Character &amp; meaning<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"80\">\n<p>{<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>(<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>*<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>?<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>)<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>}<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>$<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"80\">\n<p>Literal character. Opening curly bracket.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>Groups the .*? <\/p>\n<p>Sub-expression. This is the opening parenthesis.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>The period indicates any character. Could be a letter, or number, a dash or underline.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>The asterisk means zero or more occurrences of the previous character.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>The question mark means do a lazy <strong>regex<\/strong> match (as opposed to a greedy pattern match).<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>Closes the grouping for the sub-expression. <\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>Literal character. Closing curly bracket.<\/p>\n<\/td>\n<td valign=\"top\" width=\"80\">\n<p>Matches previous character only at the end of a line. Therefore, are looking for closing curly brackets that are found at end of line.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Because there is only one active power plan, it is possible to retrieve the <strong>InstanceID<\/strong> directly, and then convert it to a string. In the Get-ActivePowerPlanSettingsPwrCfg.ps1 script, I did not do this. Rather, I stored the entire object in the <strong>$plan<\/strong> variable. But for testing from the command line, this works out well. <strong>$guid<\/strong> will contain the following information:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Microsoft:PowerPlan\\{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<\/blockquote>\n<p>After the <strong>InstanceID<\/strong> has been converted to a string and stored in the<strong> $guid<\/strong> variable, the <strong>regex<\/strong> pattern is assigned to a variable called <strong>$regex<\/strong>. To create our regular expression pattern, we place the pattern inside a pair of quotation marks, and use the <strong>[regex]<\/strong> type accelerator to &ldquo;cast&rdquo; the string to a <strong>regex<\/strong> object. You can use the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.object.gettype.aspx\">gettype method<\/a> to check on the type object that has been created. This is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.gettype()<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<p><span style=\"color: #808080\"><\/p>\n<div class=\"code\"><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<p><\/span><span style=\"color: #000000\">IsPublic<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">IsSerial<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">BaseType<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">Regex<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">System.Object<\/span><span style=\"color: #808080\"> <\/span><\/p><\/blockquote>\n<p>The <strong>match<\/strong> method from the <strong>regex<\/strong> object is used to perform the regular expression pattern match on the string that is supplied to the method call. The method returns a <strong>match<\/strong> object from the <strong>System.Text.RegularExpressions<\/strong> namespace. The <strong>match<\/strong> object has a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb774094(VS.85).aspx\">number of methods<\/a> and properties that are all listed here. <strong>GM<\/strong> is an alias for <strong>Get-Member<\/strong> and is used to show the members (methods and properties) of the match object: <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"font-size: xx-small\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">gm<\/span><span style=\"color: #808080\"> <\/span><\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><span style=\"font-size: xx-small\"><\/span><\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><span style=\"font-size: xx-small\"><span style=\"color: #000000\">&nbsp;&nbsp; TypeName:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.Text.RegularExpressions.Match<\/span><span style=\"color: #808080\"> <\/span><\/span><\/span><\/div>\n<p><span style=\"color: #808080\"><\/p>\n<div class=\"code\"><span style=\"font-size: x-small\"><br \/><span style=\"font-size: xx-small\"><\/span><\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"font-size: xx-small\"><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">MemberType<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">Definition<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Equals<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">bool<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Equals(System.Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">obj)<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">GetHashCode<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">int<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GetHashCode()<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">GetType<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">type<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">GetType()<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">NextMatch<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Text.RegularExpressions.Match<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">NextMatch()<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Result<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">string<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Result(string<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">replacement)<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">ToString&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Method<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">string<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">ToString()<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Captures<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Text.RegularExpressions.CaptureCollection<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Captures<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8230;<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Text.RegularExpressions.GroupCollection<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Groups<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{get<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">}<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Index&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Int32<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Index<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{get<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">}<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Length<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Int32<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Length<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{get<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">}<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Success<\/span><span style=\"color: #808080\">&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">System.Boolean<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Success<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{get<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">}<\/span><\/span><span style=\"font-size: xx-small\"><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Value<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<\/span><span style=\"color: #000000\">Property<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">System.String<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Value<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{get<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">}<\/span> <\/span><\/div>\n<p><\/span><\/p><\/blockquote>\n<p>The cool thing about Windows PowerShell is that the <strong>match<\/strong> object that is returned by calling the <strong>match<\/strong> method from the <strong>regex<\/strong> class automatically expands to display the values of each of the properties. This sequence of commands is shown here, and illustrates how I went from the WMI object to retrieving the GUID:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">-Filter<\/span><span style=\"color: #808080\"> &#8220;isActive=&#8217;true'&#8221;<\/span><span style=\"color: #000000\">).InstanceID.tostring()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[regex]<\/span><span style=\"color: #808080\">&#8220;{(.*?)}$&#8221; <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #000000\">Groups<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30},<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fc<\/span><span style=\"color: #000000\">fd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Success<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Captures<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Index<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Length&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">38<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Value<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span> <\/div>\n<\/blockquote>\n<p>The last thing we need to hone in on is the fact that the <strong>Groups<\/strong> property actually returns two different values. The first one is the GUID with the <strong>{ }<\/strong> that were the delimiters for the <strong>regex<\/strong> pattern. The curly brackets will mess up the call to <strong>powercfg<\/strong>, and therefore it is necessary to remove them. This is where the subexpression came into play. If the <strong>regex<\/strong> pattern had been <strong>&ldquo;{.*?}$&rdquo;<\/strong> without the <strong>( )<\/strong> that were used in our actual pattern, the second group would not have been created. This is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[regex]<\/span><span style=\"color: #808080\">&#8220;{.*}$&#8221; <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<p><span style=\"color: #808080\"><\/p>\n<div class=\"code\"><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<p><\/span><span style=\"color: #000000\">Groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Success<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Captures&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Index&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Length&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">38<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Value<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <\/span><\/p><\/blockquote>\n<p>It would therefore be necessary to come back and remove the <strong>{ }<\/strong> from the match value. Because our <strong>regex<\/strong> pattern <strong>{(.*?)}$<\/strong> contains the sub-expression and therefore returns the second group match, we can index into the collection of groups and choose the second group, the one without the <strong>{ }<\/strong> surrounding the GUID. When we have the specific group, the value can be directly retrieved. This is shown here. First, I use WMI to store the <strong>InstanceID<\/strong> as a string in the <strong>$guid<\/strong> variable. Next, I create the <strong>regex<\/strong> pattern and call the <strong>Match<\/strong> method. Next, I select only the second match group, and finally I display the value of that group:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_powerplan<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">root\\cimv2\\power<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Fi<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">lter<\/span><span style=\"color: #808080\"> &#8220;isActive=&#8217;true'&#8221;<\/span><span style=\"color: #000000\">).InstanceID.tostring()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[regex]<\/span><span style=\"color: #808080\">&#8220;{(.*?)}$&#8221; <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <\/span><span style=\"color: #808080\"><span style=\"color: #808080\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #000000\">Success<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Captures<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Index<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">21<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Length<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">36<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fcfd30<\/span><span style=\"color: #808080\"> <\/span><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">).groups[<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">]<\/span><span style=\"color: #808080\"> <\/span><\/span><span style=\"color: #000000\">Groups&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30},<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fc<\/span><span style=\"color: #000000\">fd30}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Success&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Captures<\/span><span style=\"color: #808080\">&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Index<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Length&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">38<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Value<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{1bef50e5-557d-4b3b-9b29-cdde74fcfd30}<\/span><span style=\"color: #808080\"> <\/span><\/div>\n<div class=\"code\"><span style=\"color: #808080\"><br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$regex<\/span><span style=\"color: #000000\">.Match(<\/span><span style=\"color: #2b91af\">$guid<\/span><span style=\"color: #000000\">).groups[<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">].value<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">1bef50e5-557d-4b3b-9b29-cdde74fcfd30<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<div class=\"code\"><\/div>\n<\/blockquote>\n<p>The last thing that is done is to use <strong>powercfg<\/strong> to perform a query for the particular power plan. This is a straightforward command as is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">powercfg<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-query<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$planGuid<\/span> <\/div>\n<\/blockquote>\n<p>The results from running the Get-ActivePowerPlanSettingsPwrCfg.ps1 script are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4048.HSG08311002_07D7F9EA.jpg\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"Image of results of running script\" border=\"0\" alt=\"Image of results of running script\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4150.HSG08311002_thumb_0E1ED078.jpg\" width=\"604\" height=\"452\" \/><\/a> <\/p>\n<p>&nbsp;<\/p>\n<p>LC, that is all there is to using WMI and regular expressions to retrieve the active power plan GUID. WMI Week will continue tomorrow when we continue working with WMI power classes. <\/p>\n<p>We invite you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: Use Windows PowerShell to retrieve the power plan settings for your computer. The Microsoft Scripting Guys show you how. &nbsp; Hey, Scripting Guy! I need to have a way to easily retrieve the power plan settings for the active power plan on my computer. I would like to have an easy to read [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,173,174,3,4,21,45,6],"class_list":["post-17261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-power-management","tag-regular-expressions","tag-scripting-guy","tag-scripting-techniques","tag-string-manipulation","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: Use Windows PowerShell to retrieve the power plan settings for your computer. The Microsoft Scripting Guys show you how. &nbsp; Hey, Scripting Guy! I need to have a way to easily retrieve the power plan settings for the active power plan on my computer. I would like to have an easy to read [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17261","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=17261"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17261\/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=17261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}