Files
Infra-LAB/projects/MDT/Scripts/SupportHDF/ps1/ConfigureBIOSLenovo_TSIntegration.ps1
T

105 lines
4.3 KiB
PowerShell

# ConfigureBIOSLenovo_TSIntegration.ps1
# Applique les paramètres BIOS Lenovo via le module SetBIOS
# Mode ZÉRO TOUCH - Pas d'interaction utilisateur
# Utilise une variable MDT BIOSPassword pour authentification automatique
Write-Output "[INFO] ========== Démarrage de la configuration BIOS Lenovo (Zéro Touch) =========="
# Déterminer le modèle Lenovo et sélectionner le fichier CSV approprié
$LenovoModel = $env:LenovoModel
if ([string]::IsNullOrEmpty($LenovoModel)) {
try {
$LenovoModel = (Get-WmiObject Win32_ComputerSystemProduct -ErrorAction Stop).Name
Write-Output "[INFO] LenovoModel obtenu via WMI: $LenovoModel"
}
catch {
Write-Output "[WARN] Impossible de déterminer le modèle Lenovo - utilisation de la valeur par défaut Gen 3"
$LenovoModel = "Gen 3"
}
}
# Déterminer le fichier CSV selon la génération
if ($LenovoModel -like "*Gen 5*" -or $LenovoModel -like "*Gen5*" -or $LenovoModel -like "*gen 5*" -or $LenovoModel -like "*gen5*") {
Write-Output "[INFO] Détection ThinkCentre neo 50s Gen 5 ($LenovoModel)"
$CSVFile = "%DEPLOYROOT%\Scripts\SupportHDF\CSV\ConfigBIOSLenovo_Gen5.csv"
} elseif ($LenovoModel -like "*Gen 4*" -or $LenovoModel -like "*Gen4*" -or $LenovoModel -like "*gen 4*" -or $LenovoModel -like "*gen4*") {
Write-Output "[INFO] Détection ThinkCentre neo 50s Gen 4 ($LenovoModel)"
$CSVFile = "%DEPLOYROOT%\Scripts\SupportHDF\CSV\ConfigBIOSLenovo_Gen4.csv"
} else {
Write-Output "[INFO] Détection ThinkCentre neo 50s Gen 3 ou antérieur ($LenovoModel)"
$CSVFile = "%DEPLOYROOT%\Scripts\SupportHDF\CSV\ConfigBIOSLenovo_Gen3.csv"
}
# Remplacer %DEPLOYROOT% par la vraie valeur
$CSVFile = $CSVFile -replace "%DEPLOYROOT%", $env:DEPLOYROOT
# Vérifier que le fichier CSV existe
if (!(Test-Path $CSVFile)) {
Write-Output "[ERROR] Fichier CSV non trouvé: $CSVFile"
exit 1
}
Write-Output "[INFO] Utilisation du fichier CSV: $CSVFile"
# Charger le module SetBIOS
$SetBIOSModule = Join-Path $env:DEPLOYROOT "Tools\Modules\SetBIOS\1.0\SetBIOS.psm1"
if (!(Test-Path $SetBIOSModule)) {
Write-Output "[ERROR] Module SetBIOS non trouvé: $SetBIOSModule"
exit 1
}
try {
Import-Module $SetBIOSModule -ErrorAction Stop -Force
Write-Output "[INFO] Module SetBIOS importé avec succès"
} catch {
Write-Output "[ERROR] Impossible d'importer le module SetBIOS: $_"
exit 1
}
# Récupérer le mot de passe BIOS depuis les variables MDT
$BIOSPassword = $env:BIOSPassword
if ([string]::IsNullOrEmpty($BIOSPassword)) {
Write-Output "[WARN] Variable MDT BIOSPassword non trouvée"
}
# Vérifier si un mot de passe BIOS est configuré sur le système
Write-Output "[INFO] Vérification de l'état du mot de passe BIOS..."
try {
$BIOSPasswordSettings = Get-WmiObject -Class Lenovo_BiosPasswordSettings -Namespace root\wmi -ErrorAction Stop
$PasswordState = $BIOSPasswordSettings.PasswordState
Write-Output "[INFO] État du mot de passe BIOS: $PasswordState (0=Pas de mot de passe, 1=Admin, 2=Système, 3=Utilisateur)"
$IsPasswordSet = ($PasswordState -eq 2 -or $PasswordState -eq 1 -or $PasswordState -eq 3)
} catch {
Write-Output "[WARN] Impossible de vérifier l'état du mot de passe BIOS via WMI: $_"
$IsPasswordSet = $false
}
# Vérifier cohérence mot de passe
if ($IsPasswordSet -and [string]::IsNullOrEmpty($BIOSPassword)) {
Write-Output "[ERROR] Un mot de passe BIOS est configuré mais la variable MDT BIOSPassword est vide"
Write-Output "[ERROR] Ajoutez 'BIOSPassword=VOTRE_MOT_DE_PASSE' dans CustomSettings.ini"
exit 1
}
# Exécuter Set-BIOS avec le fichier CSV - Zéro Touch
try {
Write-Output "[INFO] Application des paramètres BIOS Lenovo..."
if ($IsPasswordSet -and -not [string]::IsNullOrEmpty($BIOSPassword)) {
Write-Output "[INFO] Application des paramètres avec authentification BIOS..."
Set-Bios -CSV $CSVFile -PasswordValue $BIOSPassword -ErrorAction Stop
} else {
Write-Output "[INFO] Application des paramètres BIOS sans authentification..."
Set-Bios -CSV $CSVFile -ErrorAction Stop
}
Write-Output "[INFO] ========== Paramètres BIOS appliqués avec succès (Zéro Touch) =========="
exit 0
} catch {
Write-Output "[ERROR] Erreur lors de l'application des paramètres BIOS: $_"
Write-Output "[ERROR] ========== Configuration BIOS échouée =========="
exit 1
}