Scripts/Get-PCEnclosure.ps1
Function Get-PCEnclosure { <# .SYNOPSIS Get the system's type of enclosure .DESCRIPTION Get the system's type of enclosure .PARAMETER ComputerName The target computer name .EXAMPLE Get-PCEnclosure -ComputerName LabPC2024 .NOTES N/A .LINK N/A #> [CmdletBinding ()] Param ( [Parameter (Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter computer name' ) ] [String[]]$ComputerName ) BEGIN { $Types = ('Other', 'Unknown' ,'Desktop', 'Low Profile Desktop', 'Pizza Box', 'Mini Tower', 'Tower', 'Portable', 'Laptop', 'Notebook', 'Hand Held', 'Docking Station', 'All In One', 'Sub Notebook', 'Space Saving', 'Lunch Box', 'Main System Chassis', 'Expansion Chassis', 'Sub Chassis', 'Bus Expansion Chassis', 'Peripheral Chassis', 'Storage Chassis', 'Rack Mount Chassis', 'Sealed-Case PC', 'Multi-system Chassis', 'Compact PCI', 'Advanced TCA', 'Blade', 'Blade Enclosure', 'Tablet', 'Convertible', 'Detachable', 'IoT Gateway', 'Embedded PC', 'Mini PC', 'Stick PC') Function Show-Output ($Computer, $Values, $Status) { [PSCustomObject]@{ ComputerName = $Computer ChassisType = $Types[$($Values.ChassisTypes) - 1] Manufacturer = $Values.Manufacturer SerialNumber = $Values.SerialNumber Status = $Status } } } PROCESS { ForEach ($Computer In $ComputerName) { If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { Try { $Data = Get-WmiObject Win32_SystemEnclosure -ComputerName $Computer | Select-Object * ForEach ($Item In $Data) { Show-Output $Computer.ToUpper() $Item 'Ok' } } Catch { Show-Output $Computer.ToUpper() $Null $PSItem.Exception.Message } } Else { Show-Output $Computer.ToUpper() $Null 'Unreachable' } } } END {} } |