Powershell/WSUS/update-Approuve.ps1
2023-07-04 12:59:44 +02:00

85 lines
2.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<#
.SYNOPSIS
<Overview of script>
.NOTES
Version: 1.0
Author: Hubert CORNET
Creation Date: <Date>
Purpose/Change: Initial script development
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.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 = "<script_name>.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 $_.PublicationState -ne "Expired" ) -and ($_.ProductFamilyTitles -eq "Windows") -and ($_.UpdateClassificationTitle -eq "Security Updates" -or $_.UpdateClassificationTitle -eq "Critical Updates" -or $_.UpdateClassificationTitle -eq "Updates" -or $_.UpdateClassificationTitle -eq "Update Rollups")}
# 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