Test-WMiSMUGIsLaptop.psm1

function Test-IsLaptop {
    <#
    .SYNOPSIS
        return a boolean for if a machine is a laptop
    .DESCRIPTION
        return a boolean for if a machine is a laptop
    .PARAMETER Computer
        computer to query
    .PARAMETER cimsession
        cimsession to query
    .EXAMPLE
        C:\PS> test-islaptop
        returns local computer laptop status
    .EXAMPLE
        C:\PS>
        Another example of how to use this cmdlet
    #>

    [CmdletBinding(DefaultParameterSetName = 'ComputerName')]
    [Alias('Test-WMiSMUGIsLaptop')]
    param (
        [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true, ParameterSetName = 'ComputerName')]
        [Alias('Connection', 'PSComputerName', 'PSConnectionName', 'IPAddress', 'ServerName', 'HostName', 'DNSHostName')]
        [string[]]$ComputerName = $env:COMPUTERNAME,
        [Parameter(Mandatory = $false, ParameterSetName = 'CimSession')]
        [CimSession[]]$CimSession
    )
    begin {
        $GetEnclosureSplat = @{
            ClassName = 'Win32_SystemEnclosure'
        }
        $LaptopChassisTypes = '8', '9', '10', '11', '14', '18', '21'
        Write-Debug "Valid laptop chassis types [`$LaptopChassisTypes= $([string]::Format("'{0}'", [string]::Join("', '", $LaptopChassisTypes)))]"
    }
    process {
        foreach ($Connection in (Get-Variable -Name $PSCmdlet.ParameterSetName -ValueOnly -Scope Local)) {
            Write-Debug "Checking chassis type by leveraging $($PSCmdlet.ParameterSetName) parameter on Get-CimInstance"
            $Computer = switch ($PSCmdlet.ParameterSetName) {
                'ComputerName' {
                    $Connection
                }
                'CimSession' {
                    $GetEnclosureSplat[$PSCmdlet.ParameterSetName] = $Connection
                    $Connection.ComputerName
                }
            }
            Write-Debug "GetEnclosureSplat variable declaration complete"
            [string]$ChassisType = (Get-CimInstance @GetEnclosureSplat).ChassisTypes
            Write-Verbose ([string]::Format("{0} has a chassis type of {1}", $Computer, $ChassisType))
            [PSCustomObject]@{
                ComputerName = $Computer
                IsLaptop     = $ChassisType -in $LaptopChassisTypes
            }
        }
    }
}

Export-ModuleMember -Function Test-IsLaptop -Alias 'Test-WMiSMUGIsLaptop'