Files
Infra-LAB/projects/MDT/Scripts/Set_BIOSPassword_FromDatabase.vbs
T

154 lines
5.4 KiB
Plaintext

' =========================================================
' EXEMPLE: Set_BIOSPassword_FromDatabase.vbs
' =========================================================
' Script VBS pour récupérer le mot de passe BIOS de manière sécurisée
' À intégrer dans la séquence de tâches MDT ou DeployWiz_Initialization.vbs
'
' UTILISATION:
' 1. Adapter ce script pour votre source (BD, LDAP, fichier sécurisé, etc.)
' 2. L'ajouter en étape de prédeploiement
' 3. Le script définira la variable MDT BIOSPassword
' 4. ConfigureBIOSLenovo_TSIntegration.ps1 la récupérera automatiquement
'
' =========================================================
' Charger les objets MDT
Set objMDT = CreateObject("Microsoft.SMS.TSEnvironment")
Set objShell = CreateObject("WScript.Shell")
' Variables de diagnostic
Dim strComputer, strModel, strPassword, strSource
strComputer = objMDT("ComputerName")
strModel = ""
' =========================================================
' EXEMPLE 1: Récupérer le mot de passe depuis un fichier sécurisé
' =========================================================
Function GetPasswordFromFile()
Dim objFSO, objFile, strLine
Dim strPasswordFile
' Fichier sécurisé en lecture seule (permissions AD)
strPasswordFile = "\\serveur\partage_admin\bios_passwords.txt"
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strPasswordFile) Then
Set objFile = objFSO.OpenTextFile(strPasswordFile, 1) ' Lecture seule
Do While Not objFile.AtEndOfStream
strLine = objFile.ReadLine()
' Format du fichier: NOM_ORDINATEUR=MOTDEPASSE
If InStr(strLine, strComputer & "=") > 0 Then
GetPasswordFromFile = Split(strLine, "=")(1)
Exit Function
End If
Loop
objFile.Close()
End If
GetPasswordFromFile = ""
End Function
' =========================================================
' EXEMPLE 2: Récupérer le mot de passe depuis Active Directory
' =========================================================
Function GetPasswordFromAD()
Dim objAD, objComputer, strPassword
On Error Resume Next
Set objAD = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://<SID=" & objAD.ComputerSID & ">")
' Attribut personnalisé AD (ex: "biosPassword")
If objComputer.Get("biosPassword") <> "" Then
GetPasswordFromAD = objComputer.Get("biosPassword")
Else
GetPasswordFromAD = ""
End If
End Function
' =========================================================
' EXEMPLE 3: Récupérer depuis un appel HTTPS/JSON (API)
' =========================================================
Function GetPasswordFromAPI()
Dim objHTTP, strURL, strResponse, objJSON
' URL sécurisée HTTPS avec authentification
' Exemple: https://api.interne.com/bios/password?computer=PC001
strURL = "https://api.interne.com/bios/password?computer=" & strComputer
On Error Resume Next
Set objHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
With objHTTP
.Open "GET", strURL, False
.setRequestHeader "Authorization", "Bearer TOKEN_AUTHENTICATION"
.Send
If .Status = 200 Then
' Parser la réponse JSON (exemple simplifié)
strResponse = .ResponseText
' Implémenter le parsing JSON selon votre API
GetPasswordFromAPI = strResponse
End If
End With
End Function
' =========================================================
' RÉCUPÉRER LE MOT DE PASSE (ordre de priorité)
' =========================================================
Dim strBIOSPassword
strBIOSPassword = ""
' 1. Essayer le fichier sécurisé
strBIOSPassword = GetPasswordFromFile()
If strBIOSPassword = "" Then
WScript.Echo "[INFO] Mot de passe non trouvé dans fichier sécurisé"
End If
' 2. Essayer Active Directory
If strBIOSPassword = "" Then
strBIOSPassword = GetPasswordFromAD()
If strBIOSPassword = "" Then
WScript.Echo "[INFO] Mot de passe non trouvé dans Active Directory"
End If
End If
' 3. Essayer l'API HTTPS
If strBIOSPassword = "" Then
strBIOSPassword = GetPasswordFromAPI()
If strBIOSPassword = "" Then
WScript.Echo "[INFO] Mot de passe non trouvé via API"
End If
End If
' =========================================================
' DÉFINIR LA VARIABLE MDT
' =========================================================
If strBIOSPassword <> "" Then
objMDT("BIOSPassword") = strBIOSPassword
WScript.Echo "[INFO] Variable BIOSPassword définie avec succès"
WScript.Echo "[INFO] Ordinateur: " & strComputer
WScript.Echo "[INFO] Longueur mot de passe: " & Len(strBIOSPassword) & " caractères"
Else
WScript.Echo "[WARN] Impossible de récupérer le mot de passe BIOS"
WScript.Echo "[WARN] Déploiement sans authentification BIOS"
objMDT("BIOSPassword") = ""
End If
' =========================================================
' INTÉGRATION DANS LA SÉQUENCE MDT
' =========================================================
'
' Pour utiliser ce script:
'
' 1. Sauvegarder en tant que: %DEPLOYROOT%\Scripts\Set_BIOSPassword.vbs
' 2. Ajouter une étape "Exécuter un script" AVANT la tâche BIOS
' 3. Commande: cscript.exe "%SCRIPTROOT%\Set_BIOSPassword.vbs"
' 4. La variable MDT BIOSPassword sera disponible pour le script PowerShell
'
' =========================================================
WScript.Quit(0)