01 draft L-1

Poste admin Windows 11 — clé USB unattended

OS Cible
Progression 0% 0 / 12

Contexte

Reconstruction du poste d'admin minfra-v2 : flash d'une clé USB Windows 11 100% automatique (autounattend.xml). Étape zéro avant toute installation d'outillage.

Actions

12
  • Récupérer le repo minfra-v2 1 cmd 1 verify
    $ Commandes
    PS> # Git portable si pas encore installé (cf. 01-prerequis) winget install --id Git.Git -e --source winget --silent git clone https://github.com/sminard38/minfra-v2.git D:\git\minfra-v2 cd D:\git\minfra-v2\infra\bare-metal\win11
    ✓ Vérifications
    Test-Path D:\git\minfra-v2\infra\bare-metal\win11\autounattend.xml
  • Télécharger ISO Windows 11 1 cmd 2 verify
    $ Commandes
    PS> # Ouvre la page officielle (saisir région + édition) Start-Process "https://www.microsoft.com/software-download/windows11" # Sauvegarder sous : D:\iso\Win11_24H2_English_x64.iso
    ✓ Vérifications
    Test-Path D:\iso\Win11_24H2_English_x64.iso
    (Get-Item D:\iso\Win11_24H2_English_x64.iso).Length -gt 5GB
  • Identifier la clé USB 1 cmd 1 verify
    $ Commandes
    PS> Get-Disk | Format-Table Number, FriendlyName, @{N='Size(GB)';E={[math]::Round($_.Size/1GB,1)}}, BusType, PartitionStyle -AutoSize
    ✓ Vérifications
    (Get-Disk | Where-Object BusType -eq 'USB').Count -ge 1
  • Préparer / formater la clé USB 1 cmd 3 verify
    $ Commandes
    PS> # PowerShell admin — sélection + wipe en un bloc $d = @(Get-Disk | Where-Object { $_.BusType -eq 'USB' -or $_.MediaType -eq 'Removable Media' }) if (-not $d) { Write-Host "❌ Aucun disque amovible. Brancher la clé." -ForegroundColor Red; return } $d | Format-Table Number, FriendlyName, @{N='GB';E={[math]::Round($_.Size/1GB,1)}}, BusType, PartitionStyle -AutoSize $t = if ($d.Count -eq 1) { $d[0] } else { $d | Where-Object Number -eq [int](Read-Host "Numéro") } if (-not $t -or (Read-Host "⚠ Wipe $($t.Number) ($($t.FriendlyName), $([math]::Round($t.Size/1GB,1)) GB) ? Taper WIPE") -ne 'WIPE') { return } Set-Disk -Number $t.Number -IsReadOnly $false -ErrorAction SilentlyContinue Set-Disk -Number $t.Number -IsOffline $false -ErrorAction SilentlyContinue Clear-Disk -Number $t.Number -RemoveData -RemoveOEM -Confirm:$false if ((Get-Disk -Number $t.Number).PartitionStyle -eq 'RAW') { Initialize-Disk -Number $t.Number -PartitionStyle GPT } else { Set-Disk -Number $t.Number -PartitionStyle GPT -ErrorAction SilentlyContinue } $Global:DiskNumber = $t.Number Write-Host "✓ Disque $($t.Number) prêt (GPT vide, sans partition). `$DiskNumber = $($t.Number)" -ForegroundColor Green Write-Host " Pas de lettre Explorer = normal. Build-Win11Usb.ps1 va créer les partitions." -ForegroundColor DarkGray
    ✓ Vérifications
    (Get-Disk -Number 2).PartitionStyle -eq 'GPT'
    (Get-Disk -Number 2).IsReadOnly -eq $false
    (Get-Partition -DiskNumber 2 -ErrorAction SilentlyContinue).Count -eq 0
  • Valider autounattend.xml 1 cmd 1 verify
    $ Commandes
    PS> cd D:\git\minfra-v2\infra\bare-metal\win11 [xml](Get-Content .\autounattend.xml) | Out-Null Write-Host "XML OK" -ForegroundColor Green
    ✓ Vérifications
    powershell -Command "[xml](Get-Content D:\git\minfra-v2\infra\bare-metal\win11\autounattend.xml) | Out-Null"
  • Personnaliser autounattend.xml (optionnel) 1 cmd 1 verify
    $ Commandes
    PS> notepad D:\git\minfra-v2\infra\bare-metal\win11\autounattend.xml
    ✓ Vérifications
    Select-String -Path D:\git\minfra-v2\infra\bare-metal\win11\autounattend.xml -Pattern '<ComputerName>'
  • Flasher la clé USB (méthode standard, sans task) 1 cmd 2 verify
    $ Commandes
    PS> # PowerShell admin cd D:\git\minfra-v2\infra\bare-metal\win11 .\scripts\Build-Win11Usb.ps1 -IsoPath "D:\iso\Win11_24H2_English_x64.iso" -DiskNumber 2
    ✓ Vérifications
    (Get-Volume | Where-Object FileSystemLabel -eq 'WIN11_BOOT').Count -eq 1
    Test-Path "$((Get-Volume | Where-Object FileSystemLabel -eq 'WIN11_BOOT').DriveLetter):\autounattend.xml"
  • Flasher via Taskfile (alternative, si task installé) 🪟 windows 2 cmd 1 verify
    $ Commandes
    PS> winget uninstall Task.Task -e --silent choco install go-task -y refreshenv task --version
    PS> cd D:\git\minfra-v2\infra\bare-metal\win11 task list-disks task build-usb DISK_NUM=2 ISO_PATH="D:/iso/Win11_24H2_English_x64.iso"
    ✓ Vérifications
    task --version
  • Booter la machine cible en UEFI 2 verify
    ✓ Vérifications
    `UEFI : VendorCo ProductCode, Partition 1`
    machine cible boote sur écran login sacha
  • Premier login + sécurisation 1 cmd 2 verify
    $ Commandes
    PS> # PowerShell admin sur machine cible # Changer mdp depuis Bitwarden (préféré) $newPw = bw get password "win-sacha-$(hostname)" $secure = ConvertTo-SecureString $newPw -AsPlainText -Force Set-LocalUser -Name sacha -Password $secure # Effacer marqueur unattend Remove-Item C:\autounattend-done.txt -ErrorAction SilentlyContinue
    ✓ Vérifications
    Test-Path C:\autounattend-done.txt # doit retourner True juste après install
    (Get-LocalUser sacha).Enabled
  • Vérifier services post-install 1 cmd 3 verify
    $ Commandes
    PS> # WinRM (Ansible) Test-WSMan -ComputerName localhost # RDP (Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server').fDenyTSConnections # Outillage installé via Choco choco list --local-only
    ✓ Vérifications
    Test-WSMan -ComputerName localhost
    choco --version
    git --version
  • Retirer / chiffrer la clé USB 1 cmd 1 verify
    $ Commandes
    PS> # === Option A : effacer la clé après usage === $usb = Get-Disk | Where-Object BusType -eq 'USB' | Select-Object -First 1 Clear-Disk -Number $usb.Number -RemoveData -Confirm:$false # === Option B : retirer juste le XML, garder clé bootable === $bootLetter = (Get-Volume | Where-Object FileSystemLabel -eq 'WIN11_BOOT').DriveLetter Remove-Item "${bootLetter}:\autounattend.xml" -Force Remove-Item "${bootLetter}:\sources\autounattend.xml" -Force -ErrorAction SilentlyContinue
    ✓ Vérifications
    -not (Test-Path "$((Get-Volume | Where-Object FileSystemLabel -eq 'WIN11_BOOT').DriveLetter):\autounattend.xml")