Scripts/Get-PCEnclosure.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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 {}

}