<# .SYNOPSIS .NOTES Version: 1.0 Author: Hubert CORNET Creation Date: Purpose/Change: Initial script development .LINK https://www.tips-of-mine.fr .EXEMPLE .DESCRIPTION .PARAMETER .INPUTS .OUTPUTS .log> #> #---------------------------------------------------------[Initialisations]-------------------------------------------------------- # Argument à définir au lancement du script pour la sélection des serveurs Param( [string]$group ) # Définir l'action d'erreur pour continuer silencieusement $ErrorActionPreference = "SilentlyContinue" # Bibliothèques de fonctions requises #----------------------------------------------------------[Declarations]---------------------------------------------------------- # Version Script $sScriptVersion = "1.0" #Log File Info $sLogPath = "C:\Tmp" $sLogName = ".log" $sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName # Définition du Timestamp du fichier de log $Timestamp = Get-Date -Format FileDate # Définition du fichier de log $log = "C:\Exploit\Logs\Approved_Updates_$group.$Timestamp.txt" $date = Get-Date #-----------------------------------------------------------[Functions]------------------------------------------------------------ #------------------------------------------------------------[Script]-------------------------------------------------------------- cls # Connection au serveur WSUS $wsusserver = "SWADMAPPP01.fr.dgs.group" [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($wsusserver,$False,8530) # Définition des updates a approuver $updates = $wsus.GetUpdates() | ? {($_.Title -notmatch "Itanium" -and $_.Title -notmatch ".net Framework" -and $_.PublicationState -ne "Expired" ) -and ($_.ProductFamilyTitles -eq "Windows") -and ($_.UpdateClassificationTitle -eq "Critical Updates")} # Approbation des packages pour la sélection de serveur $wgroup = $wsus.GetComputerTargetGroups() | where {$_.Name -eq $group} foreach ($update in $updates) { $update.Approve(“Install”,$wgroup) } # Ecriture du fichier de log "Approved updates on $date : " | Out-File $log -append "Updates have been approved for following groups: (" + $group + ")" | Out-File $log -append "Following updates have been approved:" | Out-File $log -append $updates | Select Title,ProductTitles,KnowledgebaseArticles,CreationDate | Out-File $log –append