如何使用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。详情如下: