Skip to content

Instantly share code, notes, and snippets.

@syu5-gh
Last active February 5, 2022 23:49
Show Gist options
  • Save syu5-gh/e124d853c87a3fde6901 to your computer and use it in GitHub Desktop.
Save syu5-gh/e124d853c87a3fde6901 to your computer and use it in GitHub Desktop.
Get Power Configuration #PowerShell Script #windows
<#
.SYNOPSIS
Get Power Configuration PowerShell Script
.EXAMPLES
get_powercfg.ps1
#>
# https://msdn.microsoft.com/en-us/library/dn622955%28v=vs.85%29.aspx
$subgroup = (Get-WmiObject -Namespace root\cimv2\power -Class win32_powersettingSubgroup)
$in_subgroup = (Get-WmiObject -Namespace root\cimv2\power -Class win32_powersettingInSubgroup)
$settings = (Get-WmiObject -Namespace root\cimv2\power -Class win32_powersetting)
$active_plan = (Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerPlan) | Where-Object IsActive -EQ True
$possible_value = (Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingDefinitionPossibleValue)
$range_data = (Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingDefinitionRangeData)
$settings_data_idx = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingDataIndex
# Microsoft:PowerSettingDataIndex\{a1841308-3541-4fab-bc81-f71556f20b4a}\DC\{cfeda3d0-7697-4566-a922-a9086cd49dfa}
# [Power Plan]`````````````````````````````````````` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [settings]
$current_plan_id = ($active_plan.InstanceID | Select-String -Pattern "{.*}").Matches.Value
$str = "Microsoft:PowerSettingDataIndex\\" + $current_plan_id
$current_plan_settings_data_idx = ($settings_data_idx | Where-Object InstanceID -Match $str)
$output=@()
$current_plan_settings_data_idx | ForEach-Object {
$match_groups = ($_.InstanceID | Select-String -Pattern "([A|D]C)\\({[0-z\\-]*})" -AllMatches).Matches.Groups
$setting_item = $settings | Where-Object InstanceID -Match $match_groups[2].Value
$in_subgroup_item = $in_subgroup | Where-Object PartComponent -Match $match_groups[2].Value
$subgroup_match_groups = ($in_subgroup_item.GroupComponent | Select-String -Pattern "({[0-z\\-]*})" -AllMatches).Matches.Groups
if ($subgroup_match_groups -ne $null) {
$subgroup_item = $subgroup | Where-Object InstanceID -Match $subgroup_match_groups[1].Value
}else {
$subgroup_item = $null
}
$value_elem_name = $possible_value | Where-Object InstanceID -Match $match_groups[2].Value | Where-Object SettingIndex -EQ $_.SettingIndexValue
$r = $range_data | Where-Object InstanceID -Match $match_groups[2].Value
$o = New-Object psobject |
Add-Member -Name ID -MemberType NoteProperty -Value $match_groups[0].value -PassThru |
Add-Member -Name SubgroupElementName -MemberType NoteProperty -Value $subgroup_item.ElementName -PassThru |
Add-Member -Name SubgroupDescription -MemberType NoteProperty -Value $subgroup_item.Description -PassThru |
Add-Member -Name ElementName -MemberType NoteProperty -Value $setting_item.ElementName -PassThru |
Add-Member -Name Description -MemberType NoteProperty -Value $setting_item.Description -PassThru |
Add-Member -Name SettingIndexValue -MemberType NoteProperty -Value $_.SettingIndexValue -PassThru
if ($r -ne $null) {
Add-Member -inputobject $o -Name RangeDescription -MemberType NoteProperty -Value $r[0].Description
$valmin = $r | Where-Object ElementName -eq "ValueMin"
if ($valmin -ne $null) {
Add-Member -inputobject $o -Name ValueMin -MemberType NoteProperty -Value $valmin.SettingValue
}
$valmax = $r | Where-Object ElementName -eq "ValueMax"
if ($valmax -ne $null) {
Add-Member -inputobject $o -Name ValueMax -MemberType NoteProperty -Value $valmax.SettingValue
}
}
Add-Member -inputobject $o -Name ValueElementName -MemberType NoteProperty -Value $value_elem_name.ElementName
$output += $o
}
# $output | out-gridview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment