$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss' $LogFile = "$env:TEMP\WTurn-Configure-DNS-$timestamp.log" function Write-Log { param([string]$Message) $Entry = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $Message" Add-Content -Path $LogFile -Value $Entry Write-Host $Entry } try { Write-Host "`n========================================" -ForegroundColor Cyan Write-Host "CONFIGURATION DNS - W-TURN.LAN" -ForegroundColor Cyan Write-Host "========================================`n" -ForegroundColor Cyan Write-Log "===== DEBUT CONFIGURATION DNS =====" Write-Log "Computer: $env:COMPUTERNAME" Write-Log "User: $env:USERNAME" # Verification droits admin $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($currentUser) $isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "`nERREUR: Ce script necessite les droits administrateur!" -ForegroundColor Red Write-Host "Clic droit sur le fichier .bat > Executer en tant qu'administrateur`n" -ForegroundColor Yellow Write-Log "ERREUR: Pas de droits admin" Read-Host "Appuyez sur Entree pour quitter" exit 1 } Write-Log "Admin: OK" Write-Host "Droits administrateur: OK`n" -ForegroundColor Green # Detecter les interfaces reseau actives Write-Log "Detection des interfaces reseau..." Write-Host "Detection des interfaces reseau actives..." -ForegroundColor Yellow $adapters = Get-NetAdapter | Where-Object { $_.Status -eq "Up" -and $_.InterfaceDescription -notlike "*Virtual*" -and $_.InterfaceDescription -notlike "*Loopback*" } if ($adapters.Count -eq 0) { Write-Host "`nERREUR: Aucune interface reseau active trouvee!" -ForegroundColor Red Write-Log "ERREUR: Aucune interface active" Read-Host "Appuyez sur Entree pour quitter" exit 1 } Write-Host "`nInterfaces trouvees:" -ForegroundColor Cyan foreach ($adapter in $adapters) { Write-Host " - $($adapter.Name) ($($adapter.InterfaceDescription))" -ForegroundColor White Write-Log "Interface: $($adapter.Name)" } # Configuration DNS sur chaque interface active $DnsPrimary = "192.168.100.250" $DnsSecondary = "192.168.1.254" Write-Host "`nConfiguration DNS:" -ForegroundColor Yellow Write-Host " DNS Primaire: $DnsPrimary (DC W-TURN.LAN)" -ForegroundColor White Write-Host " DNS Secondaire: $DnsSecondary (Routeur)`n" -ForegroundColor White foreach ($adapter in $adapters) { try { Write-Log "Configuration DNS pour: $($adapter.Name)" Write-Host "Configuration de: $($adapter.Name)..." -ForegroundColor Yellow Set-DnsClientServerAddress -InterfaceAlias $adapter.Name -ServerAddresses ($DnsPrimary, $DnsSecondary) -ErrorAction Stop Write-Host " OK DNS configure!" -ForegroundColor Green Write-Log "DNS OK pour $($adapter.Name)" # Afficher la config $dnsConfig = Get-DnsClientServerAddress -InterfaceAlias $adapter.Name -AddressFamily IPv4 if ($dnsConfig.ServerAddresses) { Write-Host " Serveurs DNS:" -ForegroundColor Cyan foreach ($dns in $dnsConfig.ServerAddresses) { Write-Host " - $dns" -ForegroundColor White } } Write-Host "" } catch { $errmsg = $_.Exception.Message Write-Host " ERREUR: $errmsg" -ForegroundColor Red Write-Log "ERREUR pour $($adapter.Name): $errmsg" } } # Vider le cache DNS Write-Host "Vidage du cache DNS..." -ForegroundColor Yellow Write-Log "Flush DNS cache" Clear-DnsClientCache Write-Host " OK Cache DNS vide`n" -ForegroundColor Green # Test de resolution DNS Write-Host "Test de resolution DNS..." -ForegroundColor Yellow Write-Log "Test resolution base.w-turn.lan" try { $dnsTest = Resolve-DnsName -Name "base.w-turn.lan" -Type A -ErrorAction Stop $dnsip = $dnsTest.IPAddress Write-Host " OK base.w-turn.lan resolu: $dnsip" -ForegroundColor Green Write-Log "DNS resolu: $dnsip" } catch { Write-Host " ATTENTION: base.w-turn.lan non resolu" -ForegroundColor Yellow Write-Host " Verifiez que le DC est accessible (ping 192.168.100.250)" -ForegroundColor Yellow Write-Log "DNS non resolu: $($_.Exception.Message)" } Write-Log "===== FIN CONFIGURATION - SUCCES =====" Write-Host "`n========================================" -ForegroundColor Green Write-Host "CONFIGURATION DNS TERMINEE AVEC SUCCES" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "`nFichier log cree:" -ForegroundColor Yellow Write-Host "$LogFile" -ForegroundColor Cyan Write-Host "`nVous pouvez maintenant lancer le test:" -ForegroundColor Yellow Write-Host "LANCER-Test-Diagnostic.bat`n" -ForegroundColor Cyan } catch { $errmsg = $_.Exception.Message Write-Log "ERREUR GLOBALE: $errmsg" Write-Host "`nERREUR:" -ForegroundColor Red Write-Host $errmsg -ForegroundColor Red Write-Host "`nLog: $LogFile" -ForegroundColor Yellow } Write-Host "`n" Read-Host "Appuyez sur Entree pour quitter"