首页 > 解决方案 > 如何使用 powershell 将 Powercfg /availablesleepstates 输出到对象中

问题描述

命令行输出:

C:\powercfg -availablesleepstates
The following sleep states are available on this system:
    Standby (S3)
    Hibernate
    Hybrid Sleep
    Fast Startup

The following sleep states are not available on this system:
    Standby (S1)
        The system firmware does not support this standby state.

    Standby (S2)
        The system firmware does not support this standby state.

    Standby (S0 Low Power Idle)
        The system firmware does not support this standby state.

PowerShell脚本:

$info = (powercfg /a | Select-String -Pattern "sleep states are available" -context 4) | select -Last 4
$items = $info -split ","
$ourObject = New-Object -TypeName psobject

$ourObject | Add-Member -MemberType NoteProperty -Name PCFG0bj -Value $items -Force
$ourObject | fl

Output:
PCFG0bj : {> The following sleep states are available on this system:
                Standby (S3)
                Hibernate
                Hybrid Sleep
                Fast Startup}

标签: powershellparsingcmdletpsobjectpowercfg

解决方案


推荐阅读