powershell怎么查看局域网中计算机的电源状态?

powershell怎么查看局域网中计算机的电源状态?如:是睡眠(sleep)还是唤醒状态。

阅读 1.9k
1 个回答

尝试一下:
前提是你要能ping 通

$computername = "wswincnhz0029" #将“wswincnhz0029”替换为要查询的计算机名称

Invoke-Command -ComputerName $computername -ScriptBlock {
    if ((Get-CimInstance -ClassName CIM_ComputerSystem).PCSystemType -ne 0) {
        Write-Host "The system is not a desktop or server, so the power state cannot be determined."
    }
    else {
        switch ((Get-CimInstance -ClassName CIM_LogicalElement -Namespace root\cimv2\power -Filter "instancename='\\\\\\\.\\root\\cimv2\\power\\Win32_PowerState'").SystemSuspendState) {
            'Standby' {Write-Host "The system is in Standby (Sleep) mode."}
            'Hibernate' {Write-Host "The system is in Hibernate mode."}
            default {Write-Host "The system is Awake and running."}
        }
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏