Files
Infra-LAB/projects/MDT/Scripts/WingetRepo$/Prepare-Winget.ps1
T
Almeyric ef7128111a feat: Moderniser scripts Winget pour compatibilité MDT USB
- Remplacer chemins en dur par variables dynamiques (\C:\Windows)
- Ajouter détection du contexte SYSTEM avec alertes
- Implémenter upgrade automatique Winget v7 avant installation
- Ajouter gestion d'erreurs robuste et logging détaillé
- Ignorer dossier Apps/ dans .gitignore (installers volumineux)
- Créer documentation compatibilité MDT USB
2026-06-08 18:25:44 +02:00

98 lines
3.9 KiB
PowerShell

# =========================================================================
# PREPARE-WINGET.PS1 - Configuration de Winget pour MDT SYSTEM
# =========================================================================
# Ce script doit s'exécuter en contexte SYSTEM lors du déploiement MDT
# =========================================================================
# 1. VERIFICATION DU CONTEXTE D'EXECUTION
# =========================================================================
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$IsSystem = $CurrentUser -like "*SYSTEM" -or $CurrentUser -like "*S-1-5-18"
if (-not $IsSystem) {
Write-Warning "ATTENTION: Ce script devrait s'exécuter en contexte SYSTEM"
Write-Warning "Utilisateur courant: $CurrentUser"
}
# =========================================================================
# 2. CONSTRUCTION DES CHEMINS (Dynamiques, pas en dur)
# =========================================================================
$SystemRoot = $env:SystemRoot # C:\Windows
$SystemDrive = $env:SystemDrive # C:
$WingetDataPath = "$SystemRoot\System32\config\systemprofile\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState"
Write-Host "Chemin racine système: $SystemRoot"
Write-Host "Chemin données Winget: $WingetDataPath"
# =========================================================================
# 3. CREATION DES DOSSIERS NECESSAIRES
# =========================================================================
if (!(Test-Path $WingetDataPath)) {
Write-Host "Création du dossier: $WingetDataPath"
$null = New-Item -ItemType Directory -Force -Path $WingetDataPath -ErrorAction SilentlyContinue
}
# =========================================================================
# 4. CONFIGURATION WINGET (JSON)
# =========================================================================
$SettingsFile = "$WingetDataPath\settings.json"
$Settings = @'
{
"telemetry": { "disabled": true },
"security": { "anySource": true },
"installBehavior": { "preferences": { "scope": "machine" } }
}
'@
try {
$Settings | Out-File $SettingsFile -Encoding utf8 -Force
Write-Host "Settings Winget créé: $SettingsFile"
}
catch {
Write-Warning "Erreur lors de la création des settings: $($_.Exception.Message)"
}
# =========================================================================
# 5. UPGRADE WINGET VERS V7 (avant utilisation)
# =========================================================================
Write-Host "Vérification/Upgrade de Winget..." -ForegroundColor Yellow
try {
# Tenter de mettre à jour Winget vers la dernière version
Write-Host "Mise à jour de Winget en cours..."
& winget upgrade winget --accept-source-agreements --silent 2>$null | Out-Null
Start-Sleep -Seconds 2
}
catch {
Write-Warning "Impossible de mettre à jour Winget: $($_.Exception.Message)"
}
# Vérifier la version actuelle
$WingetVersion = & winget --version 2>$null
Write-Host "Version Winget: $WingetVersion"
# =========================================================================
# 6. ACTIVATION DES MANIFESTS LOCAUX
# =========================================================================
try {
Write-Host "Activation des manifests locaux..."
& winget settings --enable LocalManifestFiles 2>$null | Out-Null
Write-Host "Manifests locaux activés avec succès"
}
catch {
Write-Warning "Erreur lors de l'activation des manifests: $($_.Exception.Message)"
}
# =========================================================================
# 7. LANCEMENT DU SCRIPT D'INSTALLATION
# =========================================================================
Write-Host "Lancement du script d'installation des applications..." -ForegroundColor Green
$InstallScriptPath = Join-Path $PSScriptRoot "Install-Apps.ps1"
if (Test-Path $InstallScriptPath) {
& "$InstallScriptPath"
}
else {
Write-Error "Script d'installation introuvable: $InstallScriptPath"
exit 1
}