Forum Discussion

shashwat001's avatar
shashwat001
Copper Contributor
May 29, 2021

Get lid open or close state using powershell

I have a home laptop to which I have remote ssh access using Powershell. How can I get whether the lid is opened or close

  • shashwat001 

     

    You can list all currently active displays by using 

    Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams

    Output:

    Then you narrow it down to the one you need, in this case my laptop screen is the one with the instance name containing 'LEN40a9'

     

    Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object InstanceName -Match 'LEN40a9'

    Then you can determine if it's open or closed by using:

     

    if ((Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object InstanceName -Match 'LEN40a9').Active -eq 'True') {
    write-host monitor lis is open} else {
    write-host Monitor lid is closed
    }

Resources