update
This commit is contained in:
84
WSUS/update-Approuve.ps1
Normal file
84
WSUS/update-Approuve.ps1
Normal file
@ -0,0 +1,84 @@
|
||||
<#
|
||||
.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
|
||||
|
Reference in New Issue
Block a user