Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用powershell将Powercfg/availablesleepstates输出到对象中_Powershell_Parsing_Cmdlet_Psobject_Powercfg - Fatal编程技术网

如何使用powershell将Powercfg/availablesleepstates输出到对象中

如何使用powershell将Powercfg/availablesleepstates输出到对象中,powershell,parsing,cmdlet,psobject,powercfg,Powershell,Parsing,Cmdlet,Psobject,Powercfg,命令行输出: 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)

命令行输出:

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}

作为正则表达式路径的替代方法,您可以调用powercfg使用的基础Win32 API,但这需要使用Add Type来编译C#代码。据我所知,您不能通过PowerShell直接调用Win32 API。更多信息:作为正则表达式路径的替代方法,您可以调用powercfg使用的基础Win32 API,但这需要使用Add Type来编译C代码。据我所知,您不能通过PowerShell直接调用Win32 API。详情如下: