Import-Module UpdateServices #SSL avec certificat non trust # Sauvegarder la configuration actuelle $OldCallback = [System.Net.ServicePointManager]::ServerCertificateValidationCallback $WSUS try { # Accepter les certificats sans validation [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } # Connexion WSUS SSL $WSUS = Get-WsusServer ` -Name "wsus.example.local" ` -PortNumber 8531 ` -UseSsl # Test de récupération des ordinateurs # Get-WsusComputer -UpdateServer $WSUS -All | # Select-Object -First 10 FullDomainName } finally { # Rétablir la validation normale [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $OldCallback } # Date limite $DateLimite = (Get-Date).ToUniversalTime().AddDays(-30) # Récupération des ordinateurs $PCs = Get-WsusComputer -UpdateServer $WSUS -All # Filtrage $Resultats = $PCs | Where-Object { $_.LastReportedStatusTime -le $DateLimite } | Select-Object ` FullDomainName, IPAddress, OSDescription, LastReportedStatusTime, LastSyncTime # Affichage de tous les hotes n'ayant pas envoyé de rapport dans les 30 derniers jours # $Resultats | Format-Table -AutoSize # $Resultats.FullDomainName # Récupération des hote qui répondent au ping $ping_ok = $Resultats | Where-Object { Test-Connection -ComputerName $_.FullDomainName -Count 1 -Quiet -ErrorAction SilentlyContinue } # On affiche $ping_ok | Format-Table -AutoSize # Executer des commandes sans retours #Invoke-Command -ComputerName $ping_ok.FullDomainName -ScriptBlock { #} foreach ($PC in $ping_ok) { Write-Host "Connexion à $($PC.FullDomainName)" -ForegroundColor Cyan try { Invoke-Command ` -ComputerName $PC.FullDomainName ` -ErrorAction Stop ` -ScriptBlock { # Commandes exécutées sur le PC distant Write-Host "Récurération des mises à jour..." Get-WindowsUpdate Write-Host "Installation des mises à jour..." Install-WindowsUpdate -AcceptAll -IgnoreReboot Write-Host "Requête d'envoi du rapport..." wuauclt /reportnow } Write-Host "Connexion réussie" -ForegroundColor Green } catch { Write-Host "Erreur sur $($PC.FullDomainName) : $_" -ForegroundColor Red } } # Export CSV #$Resultats | Export-Csv "C:\Temp\PC_Wsus_30Jours.csv" ` # -Delimiter ";" -NoTypeInformation -Encoding UTF8