Check if a machine is laptop or desktop and get model of computer using Powershell

Determine whether a machine is Laptop or not

Administrators managing an enterprise with thousands of computers need to ascertain occasionally whether a particular computer is a laptop or a desktop before pushing out updates and applications. However, doing so manually is time-consuming. This is where PowerShell scripting comes into play. The WMI class called Win32_SystemEnclosure, and the ChassisTypes property can be used to determine whether a computer is a laptop or a desktop.

How to Check if a machine is a laptop or desktop and get the model of a computer using Powershell

The Get ChassisType property actually returns a number corresponding to the computer type. If the script returns 3, the computer is a desktop, if it returns 9, a laptop, and if 10 is returned, the computer is a notebook. If you intend to use PowerShell scripts to get the hardware computer model and manufacturer details, the WMI class Win32_ComputerSystem will be of help.
 
The following PowerShell script can help determine if a machine in question is a laptop or not. 

Script
  1. <#
  2. .SYNOPSIS
  3. This script can be used to determine whether a machine is Laptop or not.
  4. .DESCRIPTION
  5. This script can be used to determine whether a machine is Laptop or not.
  6. .EXAMPLE
  7. C:\PS> C:\Script\Detect_Laptop.ps1
  8. To determine whether a machine is Laptop or not.#>
  9. Function Detect-Laptop
  10. {
  11. Param( [string]$computer = “localhost” )
  12. $isLaptop = $false
  13. #The chassis is the physical container that houses the components of a computer. Check if the machine’s chasis type is 9.Laptop 10.Notebook 14.Sub-Notebook
  14. if(Get-WmiObject -Class win32_systemenclosure -ComputerName $computer | Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 -or $_.chassistypes -eq 14})
  15. { $isLaptop = $true }
  16. #Shows battery status , if true then the machine is a laptop.
  17. if(Get-WmiObject -Class win32_battery -ComputerName $computer)
  18. { $isLaptop = $true }
  19. $isLaptop
  20. }
  21. If(Detect-Laptop) { “it’s a laptop” }
  22. else { “it’s not a laptop”}
  23. #Listing computer manufacturer and model
  24. Get-CimInstance -ClassName Win32_ComputerSystem

Post navigation


    • Related Articles

    • Determine version of Exe or Dll

      IT administrators need to compare the version information of the EXE or DLL files. This can be critical because, the version numbers indicate whether a software patch has been applied or not. However sifting through multiple version numbers of all ...
    • Determine service status and start or stop them

      Get service status and start or stop a service based on feedback received. Script <# .SYNOPSIS This script can be used to start a service or stop a service. .DESCRIPTION This script can be used to start a service or stop a service. .EXAMPLE C:\PS> ...
    • Get Screen Resolution of remote computers

      Administrators sometimes have to document certain properties of the computers in their network. The most common one is the screen resolution. Doing so on a collection of remote computers only adds to the complication. However, with the help of the ...
    • Performing bulk operations in Microsoft 365 with PowerShell

      Performing bulk operations in Microsoft 365 with PowerShell, such as bulk adding users or modifying attributes, can be a very useful and efficient way to manage your organization's users and resources. PowerShell is a powerful command-line tool that ...
    • How to create and manage Microsoft 365 groups with PowerShell

      Introduction: Microsoft 365 Groups is a collaboration feature that allows users to work together and share resources such as calendars, files, and email messages. Microsoft 365 Groups can be created and managed using the Microsoft 365 admin center, ...