PowerShell Function

Function IsLaptop {
    $isLaptop = $false
    if (Get-WmiObject -Class win32_systemenclosure | Where-Object { $_.chassistypes -eq 8 -or $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 -or $_.chassistypes -eq 14 -or $_.chassistypes -eq 30 }) {
        $isLaptop = $true
    }
    Return $isLaptop
}

If (IsLaptop) { 
    Write-Host "Laptop" 
} else {
    Write-Host "Not a Laptop"
}

Explanation of the Function

The function IsLaptop checks the chassis type of the computer to determine if it is a laptop. It returns $true if the chassis type matches known laptop types and $false otherwise. The chassis types checked are:

  • 8: Portable
  • 9: Laptop
  • 10: Notebook
  • 14: SubNotebook
  • 30: Laptop Convertible


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.