# HardwareInfo.ps1 # DeployCenter - Inventaire matériel # Compatible Windows PowerShell 5.1 / WinPE function Get-HardwareInfo { [CmdletBinding()] param() $info = [ordered]@{ Manufacturer = "Inconnu" Model = "Inconnu" SerialNumber = "Inconnu" Firmware = "Inconnu" Architecture = $env:PROCESSOR_ARCHITECTURE WinPE = $false Disks = @() Errors = @() } # Fabricant et modele du PC try { $computer = Get-CimInstance ` -ClassName Win32_ComputerSystem ` -ErrorAction Stop if ($computer.Manufacturer) { $info.Manufacturer = $computer.Manufacturer.Trim() } if ($computer.Model) { $info.Model = $computer.Model.Trim() } } catch { $info.Errors += "Modele du PC : $($_.Exception.Message)" } # Numero de serie try { $bios = Get-CimInstance ` -ClassName Win32_BIOS ` -ErrorAction Stop if ($bios.SerialNumber) { $info.SerialNumber = $bios.SerialNumber.Trim() } } catch { $info.Errors += "Numero de serie : $($_.Exception.Message)" } # Detection du firmware try { $firmwareKey = Get-ItemProperty ` -Path "HKLM:\SYSTEM\CurrentControlSet\Control" ` -Name PEFirmwareType ` -ErrorAction Stop switch ([int]$firmwareKey.PEFirmwareType) { 1 { $info.Firmware = "BIOS (Legacy)" } 2 { $info.Firmware = "UEFI" } default { $info.Firmware = "Indetermine" } } } catch { $info.Errors += "Mode firmware indisponible" } # Detection de WinPE $info.WinPE = Test-Path ` "HKLM:\SYSTEM\CurrentControlSet\Control\MiniNT" # Inventaire des disques physiques try { $disks = @(Get-Disk -ErrorAction Stop) foreach ($disk in $disks) { $operationalStatus = @($disk.OperationalStatus | ForEach-Object { [string]$_ } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) $status = if ($operationalStatus.Count -gt 0) { $operationalStatus -join ', ' } else { 'Inconnu' } $info.Disks += [PSCustomObject]@{ Index = [int]$disk.Number Model = [string]$disk.FriendlyName SizeBytes = [long]$disk.Size SizeGB = [math]::Round( ([double]$disk.Size / 1GB), 1 ) BusType = [string]$disk.BusType Status = $status HealthStatus = [string]$disk.HealthStatus } } } catch { $info.Errors += "Inventaire des disques : $($_.Exception.Message)" } # Retourner un objet exploitable par les autres modules [PSCustomObject]$info }