Files
DeployCenter/Modules/HardwareInventory.psm1
benoit 2212e25d31 Ajout de la langue anglaise
Ajout d'un README.md avec le descriptif et les instructions
L'ancien README.md s'appelle désormais CHANGELOG.md
Activation du pavé numérique par défaut pour les installations sans assistance
Nouveau design pour la fenêtre de déploiement.
Ajout de paramètre pour pouvoir procéder à une installation totalement automatisée
Ajout de paramètre pour copier au choix sources, drivers ou les deux sur C:\DeployVenter avant leur usage par DISM.
2026-10-18 04:14:17 +02:00

156 lines
5.0 KiB
PowerShell

function Get-HardwareInfo {
[CmdletBinding()]
param()
$info = [ordered]@{
Manufacturer = "Unknown"
Model = "Unknown"
SystemSKU = ""
SerialNumber = "Unknown"
Firmware = "Unknown"
Architecture = $env:PROCESSOR_ARCHITECTURE
WinPE = $false
Disks = @()
Errors = @()
}
# PC manufacturer and model
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()
}
if ($computer.SystemSKUNumber) {
$info.SystemSKU = ([string]$computer.SystemSKUNumber).Trim()
}
}
catch {
$info.Errors += "PC model: $($_.Exception.Message)"
}
# Serial number
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)"
}
# Firmware detection
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 += "Firmware mode unavailable"
}
# WinPE detection
$info.WinPE = Test-Path `
"HKLM:\SYSTEM\CurrentControlSet\Control\MiniNT"
# Physical disk inventory
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 { 'Unknown' }
$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 += "Disk inventory: $($_.Exception.Message)"
}
# Return an object that other modules can use.
[PSCustomObject]$info
}
function Write-DeployInventory {
param(
[Parameter(Mandatory=$true)][string]$InventoryDir,
[Parameter(Mandatory=$true)][string]$InventoryFile,
[AllowNull()]$HardwareInfo,
[AllowNull()][string]$DeploymentIPv4,
[AllowNull()][string]$VncPassword,
[AllowNull()][scriptblock]$LogAction = $null
)
try {
if (-not (Test-Path -LiteralPath $InventoryDir -PathType Container)) {
New-Item -Path $InventoryDir -ItemType Directory -Force | Out-Null
}
$inventory = [ordered]@{
GeneratedAt = (Get-Date).ToString('o')
DeploymentIPv4 = $DeploymentIPv4
VncPassword = $VncPassword
Hardware = $HardwareInfo
}
$json = $inventory | ConvertTo-Json -Depth 8
Set-Content -LiteralPath $InventoryFile -Value $json -Encoding UTF8
# Remove the old separate exports after writing the consolidated inventory.
$legacyInventoryFiles = @(
(Join-Path $env:TEMP 'HardwareInfo.json'),
(Join-Path $InventoryDir 'hardware.json')
)
foreach ($legacyFile in $legacyInventoryFiles) {
if (Test-Path -LiteralPath $legacyFile -PathType Leaf) {
try {
Remove-Item -LiteralPath $legacyFile -Force -ErrorAction Stop
} catch {
if ($LogAction) { & $LogAction "Unable to remove the previous inventory export '$legacyFile' : $($_.Exception.Message)" 'WARNING' }
}
}
}
} catch {
if ($LogAction) { & $LogAction "Unable to write the temporary inventory: $($_.Exception.Message)" 'WARNING' }
}
}
function Get-SelectedDeployDiskInfo {
param(
[AllowNull()]$HardwareInfo,
[Parameter(Mandatory=$true)][int]$DiskIndex
)
if ($null -eq $HardwareInfo) { return $null }
$matches = @($HardwareInfo.Disks | Where-Object { [int]$_.Index -eq $DiskIndex } | Select-Object -First 1)
if ($matches.Count -gt 0) { return $matches[0] }
return $null
}
Export-ModuleMember -Function Get-HardwareInfo, Write-DeployInventory, Get-SelectedDeployDiskInfo