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