如何从十六进制转换为具有选择对象输出的十进制

问题描述 投票:0回答:1

我陷入了 powershell 问题 - 我需要获取当前的活动电源方案,精确地在...设置后关闭显示。

我有 powercfg select-object 中的十六进制设置,但我似乎无法弄清楚如何分离当前的交流/直流计划并转换十六进制。我知道我需要使用 [int32] 将十六进制转换为十进制,但如何访问十六进制?

powercfg /QUERY | Select-String -Pattern "Turn off display after" -Context 2,8

输出为:

Subgroup GUID: 7516b95f-f776-4464-8c53-06167f40cc99  (Display)
      GUID Alias: SUB_VIDEO
>     Power Setting GUID: 3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e  (Turn off display after)
        GUID Alias: VIDEOIDLE
        Minimum Possible Setting: 0x00000000
        Maximum Possible Setting: 0xffffffff
        Possible Settings increment: 0x00000001
        Possible Settings units: Seconds
      Current AC Power Setting Index: 0x00000000
      Current DC Power Setting Index: 0x00000000

powershell scripting powercfg
1个回答
0
投票

这假设您想要提取嵌入在输出的最后两行中的十六进制数字:

[int] $ac, [int] $dc =
   (
     powercfg /QUERY |
     Select-String -Pattern 'Turn off display after' -Context 2,8 |
     ForEach-Object { $_.Context.PostContext[-2, -1] }
   ) -replace '^.+: '
© www.soinside.com 2019 - 2024. All rights reserved.