Ajout de la configuration de paritionnement des disques
This commit is contained in:
1 parent
7c724d475e
commit
e388cdca45
9 files changed
+450
-123
No files matched your search
+9
-87
@@ -73,20 +73,22 @@ function Get-HardwareInfo {
|
||||
|
||||
# Inventaire des disques physiques
|
||||
try {
|
||||
$disks = Get-CimInstance `
|
||||
-ClassName Win32_DiskDrive `
|
||||
-ErrorAction Stop
|
||||
$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.Index
|
||||
Model = $disk.Model
|
||||
Index = [int]$disk.Number
|
||||
Model = [string]$disk.FriendlyName
|
||||
SizeBytes = [long]$disk.Size
|
||||
SizeGB = [math]::Round(
|
||||
([double]$disk.Size / 1GB), 1
|
||||
)
|
||||
InterfaceType = $disk.InterfaceType
|
||||
Status = $disk.Status
|
||||
BusType = [string]$disk.BusType
|
||||
Status = $status
|
||||
HealthStatus = [string]$disk.HealthStatus
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,83 +99,3 @@ function Get-HardwareInfo {
|
||||
# Retourner un objet exploitable par les autres modules
|
||||
[PSCustomObject]$info
|
||||
}
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Execution du test
|
||||
# ============================================================
|
||||
|
||||
$LogDirectory = "X:\DeployLogs"
|
||||
$JsonPath = Join-Path $LogDirectory "hardware.json"
|
||||
$TextPath = Join-Path $LogDirectory "hardware.log"
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory `
|
||||
-Path $LogDirectory `
|
||||
-Force `
|
||||
-ErrorAction Stop | Out-Null
|
||||
}
|
||||
catch {
|
||||
throw "Impossible de creer le repertoire de logs : $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
$result = Get-HardwareInfo
|
||||
|
||||
# Export JSON en UTF-8 avec BOM sous Windows PowerShell 5.1
|
||||
try {
|
||||
$json = $result | ConvertTo-Json -Depth 5
|
||||
|
||||
Set-Content `
|
||||
-Path $JsonPath `
|
||||
-Value $json `
|
||||
-Encoding UTF8 `
|
||||
-ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
throw "Impossible d'enregistrer le JSON : $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
# Construire un journal texte sans utiliser Write-Host
|
||||
$lines = @(
|
||||
"=== DeployCenter - Inventaire materiel ==="
|
||||
"Date : $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
||||
"Fabricant : $($result.Manufacturer)"
|
||||
"Modele : $($result.Model)"
|
||||
"Numero serie : $($result.SerialNumber)"
|
||||
"Firmware : $($result.Firmware)"
|
||||
"Architecture : $($result.Architecture)"
|
||||
"WinPE : $($result.WinPE)"
|
||||
""
|
||||
"=== Disques detectes ==="
|
||||
)
|
||||
|
||||
foreach ($disk in $result.Disks) {
|
||||
$lines += (
|
||||
"Disque {0} : {1} - {2} Go - {3} - {4}" -f
|
||||
$disk.Index,
|
||||
$disk.Model,
|
||||
$disk.SizeGB,
|
||||
$disk.InterfaceType,
|
||||
$disk.Status
|
||||
)
|
||||
}
|
||||
|
||||
if ($result.Errors.Count -gt 0) {
|
||||
$lines += ""
|
||||
$lines += "=== Erreurs ==="
|
||||
|
||||
foreach ($message in $result.Errors) {
|
||||
$lines += $message
|
||||
}
|
||||
}
|
||||
|
||||
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
||||
|
||||
[System.IO.File]::WriteAllLines(
|
||||
$TextPath,
|
||||
[string[]]$lines,
|
||||
$utf8
|
||||
)
|
||||
|
||||
# Renvoyer l'objet comme sortie principale du script
|
||||
$result
|
||||
Reference in new issue
Block a user