diff --git a/.gitignore b/.gitignore index fff215c..6eba7e8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,11 @@ config*.json .env.* *.key *.pem +# Ignore local config.json +config.json + +# Ignore log files +*.log + +# Ignore CSV exports +*.csv diff --git a/Connect-IntegratedDatabase/readme.md b/Connect-IntegratedDatabase/readme.md new file mode 100644 index 0000000..50299b3 --- /dev/null +++ b/Connect-IntegratedDatabase/readme.md @@ -0,0 +1,42 @@ +# Connect to WSUS Integrated Database (WID) + +Connect locally to the WSUS Windows Internal Database (WID) via the named pipe to run maintenance or reporting against the `SUSDB` database. WID does not allow remote connections—run tools **on the WSUS server** with administrative privileges. + +## Prerequisites +- Run on the WSUS server, **elevated** (Run as Administrator). +- One of: SSMS, `sqlcmd`, or the PowerShell `SqlServer` module. +- Pipe (WID on Server 2012+): `\\.\pipe\MICROSOFT##WID\tsql\query` + Database: `SUSDB` + +## SSMS (GUI) +1. Start SSMS “Run as administrator”. +2. Server type: Database Engine + Server name: `\\.\pipe\MICROSOFT##WID\tsql\query` + Authentication: Windows Authentication +3. Connect and open a new query window. + +Quick smoke test: +```sql +SELECT @@VERSION AS SqlEngineVersion, DB_NAME() AS CurrentDatabase; +SELECT TOP (5) name, create_date FROM sys.tables ORDER BY create_date DESC; +``` +## sqlcmd (CLI) +```bat +:: Run locally on the WSUS server (elevated) +sqlcmd -S np:\\.\pipe\MICROSOFT##WID\tsql\query -d SUSDB -E -Q "SELECT TOP (1) GETDATE() AS ConnectedAt;" +``` + +## PowerShell (Invoke-Sqlcmd) +```PowerShell +Import-Module SqlServer + +$Instance = "\\.\pipe\MICROSOFT##WID\tsql\query" +$Database = "SUSDB" + +# One-liner test +Invoke-Sqlcmd -ServerInstance $Instance -Database $Database -Query "SELECT TOP (1) GETDATE() AS ConnectedAt;" + +# Run a maintenance script +$FileSql = ".\Maintenance.sql" # e.g., reindex/cleanup queries +Invoke-Sqlcmd -ServerInstance $Instance -Database $Database -InputFile $FileSql +``` \ No newline at end of file diff --git a/Dashboard/readme.md b/Dashboard/readme.md new file mode 100644 index 0000000..6f8de0d --- /dev/null +++ b/Dashboard/readme.md @@ -0,0 +1,37 @@ +# WSUS HTML Report (PowerShell) + +Generates a **single-page HTML dashboard** for WSUS: target-group inventory, KB deployment status (timeline + donuts), per-KB computer states, and a table of computers with failed updates. + +## Features +- Computers by **Target Group** (table + pie). +- KB status per group: **Installed vs Missing** and **approval age timeline**. +- Per-KB list of affected computers (hidden sections you can expand). +- **Failed** updates: computers in error. + +## Requirements +- Run on the **WSUS server** as Administrator. +- Module: `PSWriteHTML` + ```powershell + Install-Module PSWriteHTML -Scope CurrentUser + ``` +- WSUS API available (either the `UpdateServices` module or + `Microsoft.UpdateServices.Administration.dll` at + `"%ProgramFiles%\Update Services\Tools\Microsoft.UpdateServices.Administration.dll"`). +- The script uses `-Online` (CDN assets). Remove that flag if your server has no internet. + +## Quick start +```powershell +# 1) Save the script as: C:\Scripts\Wsus-Report.ps1 +# 2) Run it (elevated) +powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Wsus-Report.ps1 +# Output: +# C:\exploit\report\default.htm +``` + +## Customize +- Output path: `$outFile` (default `C:\exploit\report\default.htm`). +- Exclusions for titles (ARM64, SSU, Flash, etc.) in the KB section. +- Table/chart IDs if you embed multiple reports. + +## Full article +https://blog.wuibaille.fr/2024/10/creating-a-wsus-dashboard/ diff --git a/Dashboard/report.ps1 b/Dashboard/report.ps1 new file mode 100644 index 0000000..e2a12f0 --- /dev/null +++ b/Dashboard/report.ps1 @@ -0,0 +1,231 @@ +#Requires -RunAsAdministrator +$ErrorActionPreference = 'Stop' + +# ****************************** MODULE IMPORT & INITIALIZATION ****************************** +# HTML reporting module +Import-Module -Name PSWriteHTML -ErrorAction Stop + +Write-Host "Starting WSUS report generation..." + +# Load WSUS admin assembly explicitly (no deprecated LoadWithPartialName) +$wsusDll = "$env:ProgramFiles\Update Services\Tools\Microsoft.UpdateServices.Administration.dll" +if (Test-Path $wsusDll) { Add-Type -Path $wsusDll } else { throw "WSUS Admin DLL not found: $wsusDll" } + +# Connect to local WSUS and pull data +$wsusServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() +$updates = $wsusServer.GetUpdates() +$computers = $wsusServer.GetComputerTargets() +$targetGroups = $wsusServer.GetComputerTargetGroups() + +# Map groupId -> groupName for quick lookups +$groupHashTable = @{} +$targetGroups | ForEach-Object { $groupHashTable[$_.ID] = $_.Name } + +Write-Host "Retrieved WSUS data: Updates, Computers, and Target Groups." + +# Ensure output folder exists +$outFile = "C:\exploit\report\default.htm" +$outDir = Split-Path $outFile -Parent +if (-not (Test-Path $outDir)) { New-Item -Path $outDir -ItemType Directory -Force | Out-Null } + +# ****************************** REPORT GENERATION START ****************************** +New-HTML -TitleText 'WSUS Report' { + + # ****************************** COMPUTERS BY TARGET GROUP ****************************** + # Build a simple dataset: group name + computer count (skip 'All Computers') + $DataTable = New-Object System.Collections.Generic.List[Object] + foreach ($group in $targetGroups) { + $computersCount = $group.GetComputerTargets().Count + if ($computersCount -gt 0 -and $group.Name -ne 'All Computers') { + $DataTable.Add([PSCustomObject]@{ + TargetName = $group.Name + Total = $computersCount + }) + } + } + Write-Host "Populated DataTable with computer counts per Target Group." + + New-HTMLSection -HeaderText 'Computers By TargetGroup' { + # Table + New-HTMLPanel { + New-HTMLTable -DataTable $DataTable -HideFooter -DataTableID 'IDtargetGroup' { + # Bind events to the correct table ID + New-TableEvent -ID 'IDtargetGroup' -SourceColumnID 0 -TargetColumnId 0 + } + } + # Pie chart per group + New-HTMLPanel { + New-HTMLChart { + New-ChartToolbar -Download + foreach ($row in $DataTable) { New-ChartPie -Name $row.TargetName -Value $row.Total } + } + } + } + + # ****************************** COMPUTER LIST (HIDDEN) ****************************** + $ListeComputersWSUS = @() + foreach ($computer in $computers) { + foreach ($tg in $computer.GetComputerTargetGroups()) { + if ($tg.Name -ne 'All Computers') { + $ListeComputersWSUS += [PSCustomObject]@{ + TargetName = $tg.Name + ComputerName = $computer.FullDomainName + } + } + } + } + New-HTMLSection -HeaderText 'Computers' -Invisible { + New-HTMLTable -DataTable $ListeComputersWSUS -DataTableID 'AllComputertargetGroup' -HideFooter + } + + # ****************************** DEPLOYMENT STATUS OF KB UPDATES ****************************** + $DateNow = Get-Date + $ListeKB = @() + $MaxDaysReport = 90 # (kept for future filtering if needed) + + foreach ($update in $updates) { + foreach ($approval in $update.GetUpdateApprovals()) { + foreach ($tg in $targetGroups) { + if ($tg.Id -eq $approval.ComputerTargetGroupId) { + $DateKB = $approval.GoLiveTime + $LastChange = New-TimeSpan -Start $DateKB -End $DateNow + $ActionType = $approval.Action + + if ($ActionType -eq 'Install') { + $KBTitre = $update.Title + $installKB = 0; $MissKB = 0 + + # Summaries per group for this update + foreach ($sum in $update.GetSummaryPerComputerTargetGroup()) { + $groupName = $groupHashTable[$sum.ComputerTargetGroupId] + if ($tg.Name -eq $groupName) { + $installKB = $sum.InstalledCount + $sum.InstalledPendingRebootCount + $MissKB = $sum.UnknownCount + $sum.NotInstalledCount + $sum.DownloadedCount + $sum.FailedCount + } + } + + # Keep only meaningful KBs (exclude ARM64, SSU, Flash, specific KBs) + if (($installKB -ne 0 -or $MissKB -ne 0) -and + ($KBTitre -notmatch 'ARM64') -and + ($KBTitre -notmatch 'Servicing Stack Update') -and + ($KBTitre -notmatch 'Flash Player') -and + ($KBTitre -notlike '*KB4470788*') -and + ($KBTitre -notlike '*KB4499728*')) { + $ListeKB += [PSCustomObject]@{ + KBTitre = $KBTitre + KBGroup = $tg.Name + KBChang = $LastChange.Days + ActionType = $ActionType + installKB = $installKB + MissKB = $MissKB + } + } + } + } + } + } + } + + # Sort by age then title; get unique titles for chart grouping + $ListeKB = $ListeKB | Sort-Object KBChang, KBTitre + $groupedByTitle = @{} + foreach ($o in $ListeKB) { + if (-not $groupedByTitle.ContainsKey($o.KBTitre)) { $groupedByTitle[$o.KBTitre] = @() } + $groupedByTitle[$o.KBTitre] += $o + } + + foreach ($Title in $groupedByTitle.Keys) { + # Timeline per group (how many days since approval) + New-HTMLSection -HeaderText $Title { + New-HTMLChart -Title $Title -TitleAlignment center { + foreach ($o in $groupedByTitle[$Title]) { + New-ChartTimeline -DateFrom (Get-Date).AddDays(-$o.KBChang - 1) -DateTo (Get-Date) -Name $o.KBGroup + } + } + } + + # Donut charts (Installed vs Missing) per group – hidden + New-HTMLSection -HeaderText 'Computers' -Invisible { + foreach ($o in $groupedByTitle[$Title]) { + New-HTMLPanel { + New-HTMLChart -Title $o.KBGroup { + New-ChartLegend -Name "Installed","Missing" -Color Green,Red + New-ChartDonut -Name "Installed" -Value $o.installKB + New-ChartDonut -Name "Missing" -Value $o.MissKB + } + } + } + } + + # ------------------------- KB and Computers status table (hidden) ------------------------- + $updateScope2 = New-Object Microsoft.UpdateServices.Administration.UpdateScope + $updateScope2.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved + $updateScope2.UpdateApprovalActions = [Microsoft.UpdateServices.Administration.UpdateApprovalActions]::Install + $updateScope2.UpdateSources = [Microsoft.UpdateServices.Administration.UpdateSources]::MicrosoftUpdate + $updateScope2.ExcludedInstallationStates = @('NotApplicable','Installed','InstalledPendingReboot') + + $allComputers = $wsusServer.GetComputerTargets() + $resultsComputerStatus = @() + + foreach ($pc in $allComputers) { + $updatelist = $pc.GetUpdateInstallationInfoPerUpdate($updateScope2) + foreach ($ui in $updatelist) { + $updInfo = $ui.GetUpdate() + $approvalGroup = $ui.GetUpdateApprovalTargetGroup().Name + if ($approvalGroup -ne 'All Computers' -and $updInfo.IsApproved) { + $resultsComputerStatus += [pscustomobject][Ordered]@{ + ComputerName = $pc.FullDomainName + Status = $ui.UpdateInstallationState + ApprovalTargetGroup= $approvalGroup + Approved = $updInfo.IsApproved + Title = $updInfo.Title + } + } + } + } + + New-HTMLSection -HeaderText 'Computers' -Invisible { + foreach ($o in $groupedByTitle[$Title]) { + New-HTMLPanel { + $specific = $resultsComputerStatus | + Where-Object { $_.Title -like "*$Title*" -and $_.ApprovalTargetGroup -like "*$($o.KBGroup)*" } | + Select-Object ComputerName, Status + New-HTMLTable -DataTable $specific -HideFooter -HideButtons + } + } + } + } + + # ****************************** COMPUTERS IN ERROR ****************************** + $computersInError = @() + $updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope + $updateScope.IncludedInstallationStates = 'Failed' + $computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope + $computerScope.IncludedInstallationStates = 'Failed' + + $computersInError = $wsusServer.GetComputerTargets($computerScope) | ForEach-Object { + $compName = $_.FullDomainName + $failedTitles = ($_.GetUpdateInstallationInfoPerUpdate($updateScope) | ForEach-Object { + $_.GetUpdate().Title + }) -join ', ' + if ($failedTitles) { + [pscustomobject]@{ + Computername = $compName + TargetGroups = ($_.GetComputerTargetGroups() | Select-Object -ExpandProperty Name) -join ', ' + Updates = $failedTitles + } + } + } | Sort-Object Computername + + New-HTMLSection -HeaderText 'Computers in ERROR' { + New-HTMLTable -DataTable $computersInError -DataTableID 'NewIDtoSearchInChartERR' -HideFooter + } + + # ****************************** FOOTER ****************************** + New-HTMLFooter { + New-HTMLText -Text ("Report generated (GMT): {0:u}" -f (Get-Date).ToUniversalTime()) -Color Blue -Alignment center + } + +} -FilePath $outFile -Online + +Write-Host "WSUS report has been generated successfully at $outFile" diff --git a/auto-approval/approval.ps1 b/auto-approval/approval.ps1 new file mode 100644 index 0000000..749c1b0 --- /dev/null +++ b/auto-approval/approval.ps1 @@ -0,0 +1,123 @@ +$SyncApprovals = @( + # Sync TESTERS -> PILOT + @{ + "Source" = "Pilot" # Source group: TESTERS + "Target" = "Global1" # Target group: PILOT + "MinDays" = 5 # Minimum number of days before synchronization + }, + + # Sync PILOT -> PROD + @{ + "Source" = "Global1" # Source group: PILOT + "Target" = "Global2" # Target group: PROD + "MinDays" = 5 # Minimum number of days before synchronization + } +) + +$logFolder = "C:\logs" +$maxLogs = 60 + +# Ensure the log folder exists (create if missing) +If (-not (Test-Path $logFolder)) { + New-Item -Path $logFolder -ItemType Directory + Write-Host "The directory $logFolder has been created." +} else { + Write-Host "The directory $logFolder already exists." +} + +# Limit the number of log files (keep the most recent $maxLogs) +$logFiles = Get-ChildItem -Path $logFolder -Filter "WSUS-ManageApprovals*.log" | Sort-Object LastWriteTime -Descending +if ($logFiles.Count -gt $maxLogs) { + $logFiles | Select-Object -Skip $maxLogs | Remove-Item -Force +} + +# Build current log file path +$logFile = Join-Path $logFolder ("WSUS-ManageApprovals" + (Get-Date -format "yyyyMMdd-HHmmss") + ".log") + +# Connect to the WSUS server +Try { + [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null + $wsusServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() + $subscription = $wsusServer.GetSubscription() + $wsusServerConfig = $wsusServer.GetConfiguration() + $targetGroups = $wsusServer.GetComputerTargetGroups() + $updates = $wsusServer.GetUpdates() +} Catch { + Write-Output "Error connecting to the WSUS server: $_" | Add-Content -Path $logFile + Exit +} + +# Start a WSUS synchronization (non-blocking) +Try { + $subscription.StartSynchronization() + Write-Output "Synchronization successfully started." | Add-Content -Path $logFile +} Catch { + Write-Output "Error during WSUS synchronization: $_" | Add-Content -Path $logFile + Exit +} + +# Filter working updates (exclude declined) and accept EULAs if needed +$workingUpdates = $updates | Where-Object { -not $_.IsDeclined } +Foreach ($update in $workingUpdates) { + # Accept license agreement if required + If ($update.RequiresLicenseAgreementAcceptance) { + $update.AcceptLicenseAgreement() + Write-Output "License accepted for: $($update.Title)" | Add-Content -Path $logFile + } +} + +# Approve updates to target groups after MinDays since source approval GoLiveTime +Write-Output "********** Approve KB **********" | Add-Content -Path $logFile +Foreach ($update in $workingUpdates) { + $approvals = $update.GetUpdateApprovals() + Foreach ($syncApproval in $SyncApprovals) { + $sourceGroup = $targetGroups | Where-Object { $_.Name -eq $syncApproval.Source } + + # Ensure source group exists and action is Install + If ($sourceGroup) { + $sourceApproval = $approvals | Where-Object { $_.ComputerTargetGroupId -eq $sourceGroup.ID } + If ($sourceApproval -and $($sourceApproval.Action) -eq "Install") { + # Check if enough days have passed since GoLiveTime + $LastChangeKB = (New-TimeSpan -Start $sourceApproval.GoLiveTime -End (Get-Date)).Days + If ($LastChangeKB -ge $syncApproval.MinDays) { + $targetGroup = $targetGroups | Where-Object { $_.Name -eq $syncApproval.Target } + $targetApproval = $approvals | Where-Object { $_.ComputerTargetGroupId -eq $targetGroup.ID } + + # Approve the update if it's not already approved for installation + If ($($targetApproval.Action) -ne "Install") { + Write-Output "Approving: $($syncApproval.Target) => $($update.Title) - $LastChangeKB days" | Add-Content -Path $logFile + $update.Approve("Install", $targetGroup) | Out-Null + } + } + } + } else { + Write-Output "Source group $($syncApproval.Source) not found." | Add-Content -Path $logFile + } + } +} + +# Decline superseded updates if a superseding one is installed for the expected target groups +Write-Output "********** Disable Superseded Updates **********" | Add-Content -Path $logFile +$workingUpdates = $workingUpdates | Where-Object { $_.IsSuperseded } +Foreach ($update in $workingUpdates) { + Write-Output "$($update.Title)" | Add-Content -Path $logFile + + # Find updates that supersede the current update + Foreach ($Supersede in $update.GetRelatedUpdates([Microsoft.UpdateServices.Administration.UpdateRelationship]::UpdatesThatSupersedeThisUpdate)) { + Write-Output "----- Replaced By: $($Supersede.Title)" | Add-Content -Path $logFile + $approvals = $Supersede.GetUpdateApprovals() + + # If a superseding update is approved for Install in Global2, decline the superseded one + Foreach ($approval in $approvals) { + Foreach ($targetGroup in $targetGroups) { + If (($targetGroup.Id -eq $approval.ComputerTargetGroupId) -and ($($approval.Action) -eq "Install")) { + Write-Output "---------- $($targetGroup.Name)" | Add-Content -Path $logFile + if ($($targetGroup.Name) -eq "Global2") { # fixed: target group is Global2 + Write-Output "---------- Declining: $($update.Title)" | Add-Content -Path $logFile + $update.Decline() + } + } + } + } + } +} diff --git a/auto-approval/readme.md b/auto-approval/readme.md new file mode 100644 index 0000000..98ad3b0 --- /dev/null +++ b/auto-approval/readme.md @@ -0,0 +1,31 @@ +# WSUS – Automate Patch Assignment to Groups + +PowerShell script to automatically **promote WSUS approvals** across groups after a delay, accept EULAs, and decline superseded updates when a newer update is approved in production. + +## What it does +- Sync approvals after X days: + - `Pilot → Global1` + - `Global1 → Global2` +- Accept license agreements when required. +- Decline superseded updates if a superseding update is approved for **Global2**. +- Write rotating logs to `C:\Logs` (keeps the latest 60 files). + +## Requirements +- Run on the WSUS server with **Administrator** privileges. +- WSUS installed (PowerShell `UpdateServices` module or the WSUS Admin DLL available). +- Existing WSUS groups: `Pilot`, `Global1`, `Global2` (adjust names if different). + +## Configuration +Edit the top of the script: +- `\$SyncApprovals` – define source/target groups and `MinDays`. +- `\$logFolder`, `\$maxLogs` – logging folder and retention. +- Superseded-decline rule currently targets `Global2`. + +## Quick start +```powershell +# Run the script (no parameters) +.\Wsus-ManageApprovals.ps1 +``` + +## Full documentation +https://blog.wuibaille.fr/2024/10/automate-assign-patch-to-group/ \ No newline at end of file diff --git a/cleanup-server/CleanupWSUS.ps1 b/cleanup-server/CleanupWSUS.ps1 new file mode 100644 index 0000000..bc6b433 --- /dev/null +++ b/cleanup-server/CleanupWSUS.ps1 @@ -0,0 +1,32 @@ +#Requires -RunAsAdministrator +[CmdletBinding()] +param( + [string]$ServerName = 'localhost', + [int]$Port = 8530, + [switch]$UseSsl +) + +# Load the WSUS admin assembly explicitly if the module isn't present +$wsusDll = "$env:ProgramFiles\Update Services\Tools\Microsoft.UpdateServices.Administration.dll" +if (-not (Get-Module -ListAvailable UpdateServices)) { + if (Test-Path $wsusDll) { Add-Type -Path $wsusDll } else { throw "WSUS Admin DLL not found: $wsusDll" } +} + +try { + $wsusServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($ServerName, [bool]$UseSsl, $Port) + $cleanupInterface = $wsusServer.GetCleanupManager() + $cleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope + $cleanupScope.DeclineSupersededUpdates = $true + $cleanupScope.DeclineExpiredUpdates = $true + $cleanupScope.CleanupObsoleteComputers = $true + $cleanupScope.CleanupObsoleteUpdates = $true + $cleanupScope.CompressUpdates = $true + $cleanupScope.CleanupUnneededContentFiles = $true + + $cleanupInterface.PerformCleanup($cleanupScope) + Write-Host "WSUS cleanup completed." +} +catch { + Write-Error "WSUS cleanup failed: $($_.Exception.Message)" + exit 1 +} diff --git a/cleanup-server/readme.md b/cleanup-server/readme.md new file mode 100644 index 0000000..66d3395 --- /dev/null +++ b/cleanup-server/readme.md @@ -0,0 +1,28 @@ +# WSUS Cleanup (PowerShell) + +Powershell scripts to run a safe, repeatable **WSUS** cleanup: +- Decline superseded/expired updates +- Remove obsolete updates/computers +- Compress updates +- Delete unneeded content files + +Works with the supported WSUS cmdlets (`UpdateServices` module). A legacy .NET fallback is included. + +--- + +## Requirements +- Run on the WSUS server in an **elevated** PowerShell session. +- WSUS PowerShell module: `UpdateServices` (installed with WSUS/RSAT). +- Port **8530** (HTTP) or **8531** (HTTPS). +- Expect long runtimes on large servers; schedule outside business hours. + +## Quick start + +```powershell +# Standard full cleanup (HTTP 8530) +.\Wsus-Cleanup.ps1 -Verbose + +# HTTPS on 8531 +.\Wsus-Cleanup.ps1 -UseSsl -Port 8531 -Verbose +``` + diff --git a/generate-windows-update-log/readme.md b/generate-windows-update-log/readme.md new file mode 100644 index 0000000..f972dbe --- /dev/null +++ b/generate-windows-update-log/readme.md @@ -0,0 +1,10 @@ +# Generate a Windows Update Log + +## Procedure + +1) Generate the Windows Update log file +Use the `Get-WindowsUpdateLog` cmdlet in PowerShell to merge the Windows Update ETL files into a single log file. + +2) Locate the generated log file +`Get-WindowsUpdateLog` creates `WindowsUpdate.log` on your Desktop by default. + diff --git a/install-msu-web-download/installmsu.ps1 b/install-msu-web-download/installmsu.ps1 new file mode 100644 index 0000000..188bafb --- /dev/null +++ b/install-msu-web-download/installmsu.ps1 @@ -0,0 +1,72 @@ +# MSU Prerequisite Check and Install Script + +$LogPath = "C:\Windows\Temp\MSU_Install.log" + +function Write-Log { + param([string]$Message) + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + Add-Content -Path $LogPath -Value "$timestamp $Message" + Write-Host $Message +} + +# Check 1: Reboot pending +$RebootRegKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' +if (Test-Path $RebootRegKey) { + Write-Log "Pending reboot detected." + exit 101 +} else { + Write-Log "No pending reboot." +} + +# Check 3: Free space on C: +$minFreeGB = 5 +$drive = Get-PSDrive -Name C +if ($null -eq $drive -or ($drive.Free/1GB) -lt $minFreeGB) { + Write-Log "Insufficient free space on C:. Required: ${minFreeGB}GB" + exit 103 +} else { + Write-Log ("Sufficient free space on C:. Free: {0:N2}GB" -f ($drive.Free/1GB)) +} + +# MSU download info +$MSUFile = "windows10.0-kb5060531-x64.msu" +$MSUUrl = "https://catalog.s.download.windowsupdate.com/c/msdownload/update/software/secu/2025/06/windows10.0-kb5060531-x64_83789c3b9350e10e207370622c4ef54dd685ee02.msu" +$ScriptDir = "c:\windows\temp" +$MSUPath = Join-Path $ScriptDir $MSUFile + +# Always delete the MSU file before download +if (Test-Path $MSUPath) { + Write-Log "Deleting existing MSU file: $MSUPath" + Remove-Item -Path $MSUPath -Force -ErrorAction SilentlyContinue +} + +try { + Write-Log "Downloading MSU from $MSUUrl using System.Net.WebClient" + $sw = [System.Diagnostics.Stopwatch]::StartNew() + $wc = New-Object System.Net.WebClient + $wc.DownloadFile($MSUUrl, $MSUPath) + $sw.Stop() + $downloadTime = "{0:N2}" -f $sw.Elapsed.TotalSeconds + + if (-not (Test-Path $MSUPath)) { + Write-Log "Failed to download MSU (file not found after download)" + exit 104 + } else { + Write-Log "Download completed: $MSUPath" + Write-Log "Download time: $downloadTime seconds" + } +} catch { + Write-Log "Failed to download MSU with WebClient: $_" + exit 104 +} + +Write-Log "Starting installation of $MSUPath" + +# Install the MSU silently, no restart +$process = Start-Process -FilePath "wusa.exe" -ArgumentList "`"$MSUPath`" /quiet /norestart" -Wait -PassThru +$exitCode = $process.ExitCode + +Write-Log "wusa.exe exit code: $exitCode" + +# Return the exit code as the script's own exit code +exit $exitCode diff --git a/install-msu-web-download/installmsuv2.ps1 b/install-msu-web-download/installmsuv2.ps1 new file mode 100644 index 0000000..05d7390 --- /dev/null +++ b/install-msu-web-download/installmsuv2.ps1 @@ -0,0 +1,250 @@ +#requires -version 5.1 +<# + MSU Prereq + Install + WS logging + STRICT selection by FULL BUILD (major.UBR) + - Mapping is downloaded from https://nas.wuibaille.fr/WS/patchs/msu.json + - Supports multiple packages per build (e.g., SSU then LCU) + - JSON needs only: { "": { "packages": [ { "url": "...", "type": "LCU", "order": 20 }, ... ] } } + - No defaults: if build key missing -> exit 111 + - If JSON cannot be downloaded and no cache -> exit 112 + - If cached JSON invalid -> exit 113 +#> + +# -------- Settings -------- +$ErrorActionPreference = 'Stop' +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$ProgressPreference = 'SilentlyContinue' + +$ComputerName = $env:COMPUTERNAME +$LogPath = "C:\Windows\Temp\MSU_Install.log" +$ApiUrl = "https://nas.wuibaille.fr/WS/message.php" +$SendLogsToWS = $true + +# Remote JSON map + local cache +$MsuMapUrl = "https://nas.wuibaille.fr/WS/patchs/msu.json" +$MsuMapCache = "C:\Windows\Temp\msu.json" + +# Optional: force a build key like '17763.7786' +$OverrideBuildFull = $null + +# -------- Helpers -------- +function Write-Log { + param([Parameter(Mandatory)][string]$Message) + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + $fullMessage = "[$ComputerName] $Message" + Add-Content -Path $LogPath -Value "$timestamp $fullMessage" -Encoding UTF8 + Write-Host $fullMessage + if ($SendLogsToWS) { + try { + $body = @{ message = $fullMessage } | ConvertTo-Json -Depth 2 + $null = Invoke-RestMethod -Uri $ApiUrl -Method POST -Body $body -ContentType "application/json" -TimeoutSec 10 -ErrorAction Stop + } catch { + Write-Warning ("[$ComputerName] Webservice log failed: {0}" -f $_.Exception.Message) + } + } +} + +function Get-BuildFull { + # Returns PSCustomObject with BuildMajor, UBR, BuildFull="major.UBR" + $cvPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' + $cv = Get-ItemProperty -LiteralPath $cvPath + + $buildStr = [string]$cv.CurrentBuild + if ([string]::IsNullOrWhiteSpace($buildStr)) { $buildStr = [string]$cv.CurrentBuildNumber } + $buildMajor = [int]$buildStr + + $ubr = 0; try { $ubr = [int]$cv.UBR } catch {} + + [PSCustomObject]@{ + BuildMajor = $buildMajor + UBR = $ubr + BuildFull = ('{0}.{1}' -f $buildMajor, $ubr) + } +} + +function Get-MSUMapFromJson { + # Downloads JSON (and caches it). On failure, tries cache; else exits. + Write-Log ("Fetching MSU map: {0}" -f $MsuMapUrl) + try { + $json = Invoke-RestMethod -Uri $MsuMapUrl -Method GET -TimeoutSec 15 -ErrorAction Stop + try { ($json | ConvertTo-Json -Depth 10) | Out-File -FilePath $MsuMapCache -Encoding UTF8 -Force } catch {} + return $json + } catch { + Write-Log ("Online map fetch failed: {0}" -f $_.Exception.Message) + if (Test-Path -LiteralPath $MsuMapCache) { + Write-Log ("Using cached map: {0}" -f $MsuMapCache) + try { + $raw = Get-Content -LiteralPath $MsuMapCache -Raw -ErrorAction Stop + $json = $raw | ConvertFrom-Json -ErrorAction Stop + return $json + } catch { + Write-Log ("Cached map is invalid: {0}. Exiting 113." -f $_.Exception.Message) + exit 113 + } + } else { + Write-Log "No cached map available. Exiting 112." + exit 112 + } + } +} + +function Ensure-PackagesArray { + param( + [Parameter(Mandatory)]$Entry, + [Parameter(Mandatory)][string]$KeyForErrors + ) + <# + Accepts: + - { "packages": [ { "url": "...", "type": "LCU", "order": 20 }, ... ] } + - { "url": "..." } (single package) + - "https://..." (single package as string) + Returns: array of package objects with at least .url + #> + if ($Entry -is [string]) { + if ($Entry -notmatch '^https?://') { throw "Invalid entry for build '$KeyForErrors': expected URL string." } + return @(@{ url = $Entry; type = $null; order = $null }) + } + + $props = @($Entry.PSObject.Properties.Name) + if ($props -contains 'packages') { + $arr = @($Entry.packages) + if (-not $arr -or $arr.Count -eq 0) { throw "Entry for build '$KeyForErrors' has empty 'packages'." } + foreach ($p in $arr) { + if (-not $p.url) { throw "One package in build '$KeyForErrors' is missing 'url'." } + } + return $arr + } + + if ($props -contains 'url') { + return @(@{ url = [string]$Entry.url; type = $Entry.type; order = $Entry.order }) + } + + throw "Invalid entry format for build '$KeyForErrors'. Expected 'packages' array or 'url' string/property." +} + +function Sort-Packages { + param([Parameter(Mandatory)][array]$Packages) + # Priority: explicit 'order' asc, else by 'type' (SSU=10, LCU=20, NET=30, other=50) + $prio = @{ 'SSU' = 10; 'LCU' = 20; 'NET' = 30 } + return $Packages | Sort-Object ` + @{ Expression = { if ($_.order -ne $null -and "$($_.order)" -match '^\d+$') { [int]$_.order } else { 999 } } }, + @{ Expression = { $t = ("" + $_.type).ToUpper(); if ($prio.ContainsKey($t)) { $prio[$t] } else { 50 } } } +} + +function Resolve-PackagesForBuild { + param( + [Parameter(Mandatory)]$BuildInfo, + [Parameter(Mandatory)]$JsonMap, + [string]$OverrideBuildFull + ) + $key = if ([string]::IsNullOrWhiteSpace($OverrideBuildFull)) { $BuildInfo.BuildFull } else { $OverrideBuildFull } + + # Convert root object to hashtable keyed by build strings + $map = @{} + foreach ($p in $JsonMap.PSObject.Properties) { $map[$p.Name] = $p.Value } + + if (-not $map.ContainsKey($key)) { throw ("No MSU mapping defined for full build '{0}'." -f $key) } + + $entry = $map[$key] + $packages = Ensure-PackagesArray -Entry $entry -KeyForErrors $key + $packages = Sort-Packages -Packages $packages + return @{ Key=$key; Packages=$packages } +} + +function Test-IsAdmin { + $wi = [Security.Principal.WindowsIdentity]::GetCurrent() + $wp = [Security.Principal.WindowsPrincipal]::new($wi) + return $wp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +} + +function Filename-FromUrl { + param([Parameter(Mandatory)][string]$Url) + try { + $u = [Uri]$Url + $name = [IO.Path]::GetFileName($u.AbsolutePath) + if ([string]::IsNullOrWhiteSpace($name)) { $name = "update.msu" } + } catch { $name = "update.msu" } + if ($name -notmatch '\.msu$') { $name = "$name.msu" } + return $name +} + +# -------- Script start -------- +if (-not (Test-IsAdmin)) { Write-Log "Warning: Script is not running elevated." } + +# Build detection +$b = Get-BuildFull +Write-Log ("Detected OS: Build={0}" -f $b.BuildFull) + +# Load mapping + resolve package list +$msuJson = Get-MSUMapFromJson +try { + $sel = Resolve-PackagesForBuild -BuildInfo $b -JsonMap $msuJson -OverrideBuildFull $OverrideBuildFull + Write-Log ("Selected {0} package(s) for Build={1}" -f $sel.Packages.Count, $sel.Key) +} catch { + Write-Log ("MSU selection error: {0}. Exiting 111." -f $_.Exception.Message) + exit 111 +} + +# Checks +try { + $RebootRegKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' + if (Test-Path $RebootRegKey) { Write-Log "Pending reboot detected. Exiting 101."; exit 101 } +} catch { Write-Log ("Error while checking free space: {0}" -f $_.Exception.Message); exit 199 } + +try { + $minFreeGB = 5 + $drive = Get-PSDrive -Name C -ErrorAction Stop + $freeGB = [math]::Round(($drive.Free/1GB),2) + if ($freeGB -lt $minFreeGB) { Write-Log ("Insufficient free space: required {0}GB, available {1}GB. Exiting 103." -f $minFreeGB, $freeGB); exit 103 } +} catch { Write-Log ("Error while checking free space: {0}" -f $_.Exception.Message); exit 198 } + +# Download + install each package in order +$ScriptDir = "C:\Windows\Temp" +if (-not (Test-Path -LiteralPath $ScriptDir)) { New-Item -ItemType Directory -Path $ScriptDir -Force | Out-Null } + +$anyNeedReboot = $false +$anyInstalled = $false + +foreach ($pkg in $sel.Packages) { + $url = [string]$pkg.url + if ([string]::IsNullOrWhiteSpace($url)) { Write-Log "Package without URL encountered. Aborting (bad JSON)."; exit 113 } + $type = ("" + $pkg.type) + $fileName = Filename-FromUrl -Url $url + $destPath = Join-Path $ScriptDir $fileName + + Write-Log ("Downloading {0}{1} from {2}" -f (if ($type) { "[$type] " } else { "" }), $fileName, $url) + try { + $wc = New-Object System.Net.WebClient + try { + $wc.Headers['User-Agent'] = ("MSU-Installer/1.0 ({0})" -f $ComputerName) + if (Test-Path -LiteralPath $destPath) { Remove-Item -LiteralPath $destPath -Force -ErrorAction Stop } + $wc.DownloadFile($url, $destPath) + } finally { if ($wc) { $wc.Dispose() } } + if (-not (Test-Path -LiteralPath $destPath)) { Write-Log "Download failed: file not found after download. Exiting 104."; exit 104 } + } catch { + Write-Log ("Failed to download package {0}: {1}. Exiting 104." -f $fileName, $_.Exception.Message) + exit 104 + } + + Write-Log ("Installing {0}{1}" -f (if ($type) { "[$type] " } else { "" }), $fileName) + try { + $proc = Start-Process -FilePath "wusa.exe" -ArgumentList "`"$destPath`" /quiet /norestart" -Wait -PassThru + $code = $proc.ExitCode + Write-Log ("wusa.exe exit code: {0} for {1}" -f $code, $fileName) + + if ($code -eq 3010) { $anyNeedReboot = $true; $anyInstalled = $true } + elseif ($code -eq 0) { $anyInstalled = $true } + elseif ($code -eq 2359302) { } # already installed, continue + else { + Write-Log ("Installation failed for {0} with code {1}. Aborting." -f $fileName, $code) + exit $code + } + } catch { + Write-Log ("Installation failed for {0}: {1}" -f $fileName, $_.Exception.Message) + exit 195 + } +} + +# Overall exit code policy +if ($anyNeedReboot) { exit 3010 } +elseif ($anyInstalled) { exit 0 } +else { exit 2359302 } diff --git a/install-msu-web-download/installmsuv3.ps1 b/install-msu-web-download/installmsuv3.ps1 new file mode 100644 index 0000000..c0787e9 --- /dev/null +++ b/install-msu-web-download/installmsuv3.ps1 @@ -0,0 +1,329 @@ +#requires -version 5.1 +<# + Auto-install latest OS cumulative updates using PSWindowsUpdate (no JSON) + - Forces Windows Update public service (-WindowsUpdate) + - Installs SSU (if present) first, then latest non-Preview LCU + - ASCII-only logs; messages sanitized before sending to web service +#> + +# -------- Settings -------- +$ErrorActionPreference = 'Stop' +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$ProgressPreference = 'SilentlyContinue' + +$ComputerName = $env:COMPUTERNAME +$LogPath = "C:\Windows\Temp\MSU_Install.log" +$ApiUrl = "https://nas.wuibaille.fr/WS/message.php" +$SendLogsToWS = $true + +# Optional WS retry tunables (defaults: 6 tries, 1s delay) +$script:WsMaxRetries = 6 +$script:WsRetryDelaySec = 1 + +# Module install policy +$AllowInstallPSWindowsUpdate = $true + +# -------- Utilities -------- +function Sanitize-Ascii { + param([string]$Text) + if ($null -eq $Text) { return "" } + + $t = $Text + $t = $t -replace [char]0x2013, "-" # en dash + $t = $t -replace [char]0x2014, "-" # em dash + $t = $t -replace [char]0x2026, "..." # ellipsis + $t = $t -replace [char]0x2018, "'" # left single quote + $t = $t -replace [char]0x2019, "'" # right single quote + $t = $t -replace [char]0x201C, '"' # left double quote + $t = $t -replace [char]0x201D, '"' # right double quote + $t = $t -replace [char]0x00A0, " " # nbsp + $t = $t -replace [char]0x2022, "-" # bullet + $t = [System.Text.RegularExpressions.Regex]::Replace($t, '[^\x09\x0A\x0D\x20-\x7E]', '') + return $t +} + +# -------- Logging -------- +function Write-Log { + param([Parameter(Mandatory)][string]$Message) + + $msg = Sanitize-Ascii $Message + $full = "[$env:COMPUTERNAME] $msg" + $ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + + Add-Content -Path $LogPath -Value "$ts $full" -Encoding UTF8 + Write-Host $full + + if (-not $SendLogsToWS) { return } + + $payload = @{ message = $full } | ConvertTo-Json -Compress + $bytes = [System.Text.Encoding]::UTF8.GetBytes($payload) + + $max = if ($script:WsMaxRetries) { [int]$script:WsMaxRetries } else { 6 } + $delay = if ($script:WsRetryDelaySec) { [int]$script:WsRetryDelaySec } else { 1 } + + $ok = $false + $lastErr = $null + + for ($attempt = 1; $attempt -le $max -and -not $ok; $attempt++) { + try { + $null = Invoke-RestMethod -Uri $ApiUrl -Method POST -Body $bytes ` + -ContentType 'application/json; charset=utf-8' -TimeoutSec 10 -ErrorAction Stop + $ok = $true + } catch { + $lastErr = $_.Exception.Message + if ($attempt -lt $max) { Start-Sleep -Seconds $delay } + } + } + + if (-not $ok) { + Write-Warning "[$env:COMPUTERNAME] Webservice log failed after $max attempts: $lastErr" + } +} + +# -------- Prereqs -------- +function Test-IsAdmin { + $wi = [Security.Principal.WindowsIdentity]::GetCurrent() + $wp = [Security.Principal.WindowsPrincipal]::new($wi) + return $wp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +} + +function Get-BuildFull { + $cv = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' + $buildStr = [string]$cv.CurrentBuild + if ([string]::IsNullOrWhiteSpace($buildStr)) { $buildStr = [string]$cv.CurrentBuildNumber } + $major = [int]$buildStr + $ubr = 0; try { $ubr = [int]$cv.UBR } catch {} + [PSCustomObject]@{ BuildMajor=$major; UBR=$ubr; BuildFull=("{0}.{1}" -f $major,$ubr) } +} + +# -------- PSWindowsUpdate bootstrap (silent) -------- +function Ensure-PSWindowsUpdate { + try { + Import-Module PSWindowsUpdate -ErrorAction Stop + $m = Get-Module PSWindowsUpdate + Write-Log ("PSWindowsUpdate module loaded (v{0})." -f $m.Version) + return $true + } catch {} + + if (-not $AllowInstallPSWindowsUpdate) { + Write-Log "PSWindowsUpdate module not found and auto-install is disabled. Exiting 120." + exit 120 + } + + $scope = if (Test-IsAdmin) { 'AllUsers' } else { 'CurrentUser' } + + try { + $nuget = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue | + Sort-Object Version -Descending | Select-Object -First 1 + if (-not $nuget -or ([Version]$nuget.Version -lt [Version]"2.8.5.201")) { + Write-Log "Installing NuGet provider silently..." + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope $scope -ErrorAction Stop + } + + $repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue + if (-not $repo) { + Write-Log "Registering PSGallery repository..." + try { Register-PSRepository -Default -ErrorAction Stop } catch {} + $repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue + } + if ($repo -and $repo.InstallationPolicy -ne 'Trusted') { + Write-Log "Setting PSGallery as Trusted..." + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction SilentlyContinue + } + + try { + $psget = Get-Module -ListAvailable PowerShellGet | Sort-Object Version -Descending | Select-Object -First 1 + if (-not $psget -or ([Version]$psget.Version -lt [Version]"2.2.5")) { + Write-Log "Updating PowerShellGet silently..." + Install-Module PowerShellGet -Scope $scope -Force -AllowClobber -ErrorAction Stop + } + } catch { + Write-Log ("PowerShellGet update failed (continuing): {0}" -f $_.Exception.Message) + } + + Write-Log "Installing PSWindowsUpdate silently..." + Install-Module PSWindowsUpdate -Scope $scope -Force -AllowClobber -ErrorAction Stop + + Import-Module PSWindowsUpdate -ErrorAction Stop + $m = Get-Module PSWindowsUpdate + Write-Log ("PSWindowsUpdate installed and loaded (v{0})." -f $m.Version) + return $true + } catch { + Write-Log ("Failed to install/load PSWindowsUpdate: {0}. Exiting 120." -f $_.Exception.Message) + exit 120 + } +} + +# -------- Discovery & Install using PSWindowsUpdate -------- +function Get-AvailableOSUpdates { + # Returns: @{ SSU = ; LCU = ; Raw = } + try { + $raw = Get-WindowsUpdate -WindowsUpdate -UpdateType Software -IgnoreReboot -ErrorAction Stop + } catch { + Write-Log ("Windows Update query failed: {0}" -f $_.Exception.Message) + Write-Log "This system may be WSUS-managed or blocked by policy/network. Exiting 121." + exit 121 + } + + if (-not $raw) { + return [PSCustomObject]@{ SSU=$null; LCU=$null; Raw=@() } + } + + $filtered = $raw | Where-Object { + $_.Title -and + ($_.Title -notmatch 'Preview') -and + ($_.Title -notmatch 'for\s*\.NET') -and + ($_.Categories -notcontains 'Drivers') -and + ($_.Categories -notcontains 'Definition Updates') + } + + $norm = { + param($s) + if (-not $s) { return '' } + $t = Sanitize-Ascii $s + return $t.ToLowerInvariant() + } + + $ssu = $filtered | Where-Object { + $t = & $norm $_.Title + ($t -match 'servicing stack update' -or $t -match 'pile de maintenance') + } | Sort-Object -Property LastDeploymentChangeTime -Descending | Select-Object -First 1 + + $lcu = $filtered | Where-Object { + $t = & $norm $_.Title + ($t -match 'cumulative update' -or $t -match 'mise a jour cumulative') + } | Sort-Object -Property LastDeploymentChangeTime -Descending | Select-Object -First 1 + + [PSCustomObject]@{ SSU=$ssu; LCU=$lcu; Raw=$filtered } +} + +function Install-OneWU { + param([Parameter(Mandatory)]$UpdateObject) + + $updateId = $UpdateObject.UpdateID + $title = Sanitize-Ascii $UpdateObject.Title + $kb = $UpdateObject.KB + + $kbPrefix = if ($kb) { "$kb " } else { "" } + Write-Log ("Installing: {0}{1}" -f $kbPrefix, $title) + + try { + if ($updateId) { + $res = Install-WindowsUpdate -WindowsUpdate -UpdateID $updateId -AcceptAll -IgnoreReboot -Confirm:$false -ErrorAction Stop + } elseif ($kb) { + $res = Install-WindowsUpdate -WindowsUpdate -KBArticleID $kb -AcceptAll -IgnoreReboot -Confirm:$false -ErrorAction Stop + } else { + $res = Install-WindowsUpdate -WindowsUpdate -AcceptAll -IgnoreReboot -Confirm:$false -ErrorAction Stop | + Where-Object { (Sanitize-Ascii $_.Title) -eq $title } + } + } catch { + Write-Log ("Install failed for {0}{1}: {2}" -f $kbPrefix, $title, $_.Exception.Message) + return [PSCustomObject]@{ + Title = $title; KB = $kb; Result = 'Failed'; HResult = $null; RebootRequired = $false + } + } + + # Build a clean result array without inline 'if' + $out = @() + foreach ($o in @($res)) { + $rTitle = Sanitize-Ascii $o.Title + + $rKB = $null + if ($o.PSObject.Properties['KB'] -and $o.KB) { $rKB = $o.KB } + elseif ($o.PSObject.Properties['KBArticleID'] -and $o.KBArticleID) { $rKB = $o.KBArticleID } + + $rResult = $null + if ($o.PSObject.Properties['Result'] -and $o.Result) { $rResult = $o.Result } else { $rResult = $o.ResultCode } + + $rHResult = $null + if ($o.PSObject.Properties['HResult']) { $rHResult = $o.HResult } + + $rReboot = $false + if ($o.PSObject.Properties['RebootRequired']) { $rReboot = [bool]$o.RebootRequired } + + $out += [PSCustomObject]@{ + Title = $rTitle + KB = $rKB + Result = $rResult + HResult = $rHResult + RebootRequired = $rReboot + } + } + return ,$out # ensure array even if single item +} + +# =================== Main =================== +if (-not (Test-IsAdmin)) { Write-Log "Warning: script is not running elevated." } + +try { + $RebootRegKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' + if (Test-Path $RebootRegKey) { Write-Log "Pending reboot detected. Exiting 101."; exit 101 } +} catch { Write-Log ("Error while checking pending reboot: {0}" -f $_.Exception.Message); exit 199 } + +try { + $minFreeGB = 5 + $drive = Get-PSDrive -Name C -ErrorAction Stop + $freeGB = [math]::Round(($drive.Free/1GB),2) + if ($freeGB -lt $minFreeGB) { Write-Log ("Insufficient free space: required {0}GB, available {1}GB. Exiting 103." -f $minFreeGB, $freeGB); exit 103 } +} catch { Write-Log ("Error while checking free space: {0}" -f $_.Exception.Message); exit 198 } + +$build = Get-BuildFull +Write-Log ("Detected OS: Build={0}" -f $build.BuildFull) + +Ensure-PSWindowsUpdate | Out-Null + +$updates = Get-AvailableOSUpdates + +# Plan (pre-calc strings to avoid inline if in -f) +if ($updates.SSU) { + $kbPrefix = if ($updates.SSU.KB) { "$($updates.SSU.KB) " } else { "" } + $title = Sanitize-Ascii $updates.SSU.Title + Write-Log ("Plan: SSU -> {0}{1}" -f $kbPrefix, $title) +} +if ($updates.LCU) { + $kbPrefix = if ($updates.LCU.KB) { "$($updates.LCU.KB) " } else { "" } + $title = Sanitize-Ascii $updates.LCU.Title + Write-Log ("Plan: LCU -> {0}{1}" -f $kbPrefix, $title) +} + +if (-not $updates.SSU -and -not $updates.LCU) { + Write-Log "No OS SSU/LCU updates available (system appears up-to-date)." + exit 0 +} + +$needReboot = $false +$installed = $false +$failedAny = $false + +if ($updates.SSU) { + $r = Install-OneWU -UpdateObject $updates.SSU + foreach ($i in @($r)) { + $kbPrefix = if ($i.KB) { "$($i.KB) " } else { "" } + $hrSuf = if ($i.HResult) { " (HResult=$($i.HResult))" } else { "" } + $rbSuf = if ($i.RebootRequired) { " [RebootRequired]" } else { "" } + Write-Log ("Result: {0}{1} => {2}{3}{4}" -f $kbPrefix, $i.Title, $i.Result, $hrSuf, $rbSuf) + + if ($i.Result -match 'Succeeded') { $installed = $true } + elseif ($i.Result -match 'Failed|Aborted|Error') { $failedAny = $true } + if ($i.RebootRequired) { $needReboot = $true } + } +} + +if ($updates.LCU) { + $r = Install-OneWU -UpdateObject $updates.LCU + foreach ($i in @($r)) { + $kbPrefix = if ($i.KB) { "$($i.KB) " } else { "" } + $hrSuf = if ($i.HResult) { " (HResult=$($i.HResult))" } else { "" } + $rbSuf = if ($i.RebootRequired) { " [RebootRequired]" } else { "" } + Write-Log ("Result: {0}{1} => {2}{3}{4}" -f $kbPrefix, $i.Title, $i.Result, $hrSuf, $rbSuf) + + if ($i.Result -match 'Succeeded') { $installed = $true } + elseif ($i.Result -match 'Failed|Aborted|Error') { $failedAny = $true } + if ($i.RebootRequired) { $needReboot = $true } + } +} + +if ($failedAny) { Write-Log "One or more updates failed."; exit 195 } +if ($needReboot) { exit 3010 } +if ($installed) { exit 0 } +exit 0 diff --git a/install-msu-web-download/readme.md b/install-msu-web-download/readme.md new file mode 100644 index 0000000..89fca4b --- /dev/null +++ b/install-msu-web-download/readme.md @@ -0,0 +1,41 @@ +# MSU Direct Download & Silent Install (PowerShell) + +Download a specific **MSU** from Microsoft Update Catalog, run **pre-checks**, install with `wusa.exe /quiet /norestart`, and return the installer’s exit code. Logs to `C:\Windows\Temp\MSU_Install.log`. + +## What it checks +- **Pending reboot** → exits **101**. +- **Free space on C:** ≥ **5 GB** (default) → exits **103**. +- **Download** success from the Catalog URL → exits **104** on failure. +- Otherwise runs `wusa` and returns its native **exit code** (`0` OK, `3010` reboot required). + +## Quick start +1. Edit the variables at the top of the script: + - `$MSUUrl` (direct Catalog URL) + - `$MSUFile` (e.g. `windows10.0-kb5060531-x64.msu`) + - Optional: `$minFreeGB` +2. Run as Administrator: + ```powershell + powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Install-MSU.ps1 + ``` + +## Exit codes +- **0** = Installed successfully +- **3010** = Installed, reboot required (from `wusa`) +- **101** = Pending reboot detected +- **103** = Not enough free space on C: +- **104** = Download failed +- **others** = Native `wusa.exe` codes + +## Requirements +- Windows 10/11 or Server, **elevated** PowerShell. +- Outbound access to the Microsoft Update Catalog URL. +- `wusa.exe` available (built-in). + +## Notes +- The script deletes any existing MSU at the target path before downloading. +- If proxy/TLS blocks `WebClient`, switch to `Invoke-WebRequest` and enforce TLS 1.2: + ```powershell + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + Invoke-WebRequest -Uri $MSUUrl -OutFile $MSUPath -UseBasicParsing + ``` + diff --git a/report-failed-computers/Display.ps1 b/report-failed-computers/Display.ps1 new file mode 100644 index 0000000..da79f2d --- /dev/null +++ b/report-failed-computers/Display.ps1 @@ -0,0 +1,73 @@ +# Initializations +[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null +$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() +$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope +$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope +$summariesComputerFailed = $wsus.GetSummariesPerComputerTarget($updateScope,$computerScope) | Where-Object FailedCount -NE 0 | Sort-Object FailedCount, UnknownCount, NotInstalledCount -Descending +$computers = Get-WsusComputer +$computersErrorEvents = $wsus.GetUpdateEventHistory([System.DateTime]::Today.AddDays(-7), [System.DateTime]::Today) | Where-Object ComputerId -ne [Guid]::Empty | Where-Object IsError -eq $true + +function Get-TimeStamp { + return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date) +} + +$csvFile = "$PSScriptRoot\WSUSFailedComputer_" + "{0:MMddyy}" -f (Get-Date) + ".csv" +Get-WsusComputer -ComputerUpdateStatus Failed | Export-Csv -Path $csvFile -NoTypeInformation +$ComputersErrorToday = Get-WsusComputer -ComputerUpdateStatus Failed + +$csvList = (Get-ChildItem -Path $PSScriptRoot -Filter *.csv).FullName +$AllCsv = $csvList | Import-Csv +$AllCsv = $AllCsv | Sort-Object "FullDomainName" + +$Ordinateur = @() +$CountError = 1 +$OldComputer = "XXXX" +Foreach ($csv In $AllCsv) { + $FullDomainName = $csv.FullDomainName + + $ExitError = $true + Foreach ($ComputerErrorToday In $ComputersErrorToday) { + $FullNameComputerErrorToday = $ComputerErrorToday.FullDomainName + if ($FullNameComputerErrorToday -eq $FullDomainName) { $ExitError = $false } + } + + If (-not $ExitError) { + If ($OldComputer -eq $FullDomainName) { + $CountError += 1 + } Else { + if ($OldComputer -ne "XXXX") { + $CountError = $CountError.ToString("0000") + $Ordinateur += "$CountError;$OldComputer" + } + $CountError = 1 + $OldComputer = $FullDomainName + } + } +} + +$Ordinateur = $Ordinateur | Sort-Object -Descending +$TotalAffiche = 10 +$NbAffiche = 0 +Foreach ($Computererror In $Ordinateur) { + If ($NbAffiche -lt $TotalAffiche) { + Write-Host $Computererror + + $NbAffiche += 1 + + $NomOrdinateur = $Computererror.Substring(5) + ForEach ($computerFailed In $summariesComputerFailed) { + $computer = $computers | Where-Object Id -eq $computerFailed.ComputerTargetId + + $Computername = $computer.FullDomainName + $ComputerIP = $computer.IPAddress + + if ($Computername -eq $NomOrdinateur) { + $computerUpdatesFailed = ($wsus.GetComputerTargets($computerScope) | Where-Object Id -EQ $computerFailed.ComputerTargetId).GetUpdateInstallationInfoPerUpdate($updateScope) | Where-Object UpdateInstallationState -EQ "Failed" + ForEach ($update In $computerUpdatesFailed) { + $outputText = $wsus.GetUpdate($update.UpdateId).Title + Write-Host "------------ $outputText" + } + } + } + } +} \ No newline at end of file diff --git a/report-failed-computers/readme.md b/report-failed-computers/readme.md new file mode 100644 index 0000000..c7efbdb --- /dev/null +++ b/report-failed-computers/readme.md @@ -0,0 +1,27 @@ +# WSUS – Failed Computers (Display.ps1) +Generate a CSV of client machines that had Windows Update installation errors over a recent time window, by querying **WSUS event history (errors only)**. Faster and more accurate than stitching multiple daily exports. If the `UpdateServices` module isn’t present, the script uses the WSUS Admin .NET DLL directly. + +--- + +## Requirements + +- Run on the **WSUS server**, in an **elevated** 64-bit Windows PowerShell (5.1). +- WSUS PowerShell module `UpdateServices` (installed with WSUS/RSAT) **or** the Admin DLL: + `C:\Program Files\Update Services\Tools\Microsoft.UpdateServices.Administration.dll` +- Local access to WSUS (HTTP 8530 or HTTPS 8531). + +--- + +## Install + +1. Copy the script here: `DisplayToErrorComputer/Display.ps1` +2. Unblock if downloaded from the internet: + ```powershell + Unblock-File .\Display.ps1 + ``` + +## How to run +Standard run (last 7 days, top 100): + ```powershell + .\Display.ps1 -Days 7 -Top 100 -Verbose + ``` \ No newline at end of file diff --git a/report-top-error-computers/DisplayToError.ps1 b/report-top-error-computers/DisplayToError.ps1 new file mode 100644 index 0000000..079693d --- /dev/null +++ b/report-top-error-computers/DisplayToError.ps1 @@ -0,0 +1,61 @@ +#Requires -RunAsAdministrator +$ErrorActionPreference = 'Stop' + +# ---- Parameters ---- +$Days = 7 # time window for error events +$Top = 10 # top N computers by error count +$OutCsv = "$PSScriptRoot\WSUS_FailedComputers_{0:yyyyMMdd}.csv" -f (Get-Date) + +# ---- Connect to WSUS (module if available, else DLL) ---- +if (Get-Module -ListAvailable UpdateServices) { + Import-Module UpdateServices -ErrorAction Stop + $wsus = Get-WsusServer +} else { + $dll = "$env:ProgramFiles\Update Services\Tools\Microsoft.UpdateServices.Administration.dll" + if (-not (Test-Path $dll)) { throw "WSUS Admin DLL not found: $dll" } + Add-Type -Path $dll + $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() +} + +# ---- Pull error events in the time window ---- +$from = (Get-Date).Date.AddDays(-[int]$Days) +$to = (Get-Date).Date +$events = $wsus.GetUpdateEventHistory($from, $to) | + Where-Object { $_.IsError -and $_.ComputerId -ne [Guid]::Empty } + +# ---- Aggregate per computer and take Top N ---- +$allComputers = $wsus.GetComputerTargets() +$compById = @{}; foreach ($c in $allComputers) { $compById[$c.Id] = $c } + +$topByCount = $events | Group-Object ComputerId | + Sort-Object Count -Descending | Select-Object -First $Top + +$result = foreach ($g in $topByCount) { + $c = $compById[$g.Name] + $lastEvt = $events | Where-Object { $_.ComputerId -eq $c.Id } | + Sort-Object CreationDate -Descending | Select-Object -First 1 + [pscustomobject]@{ + ComputerName = $c.FullDomainName + IPAddress = $c.IPAddress + Errors = $g.Count + LastError = $lastEvt.CreationDate + } +} + +# ---- Output: table + CSV ---- +$result | Format-Table -AutoSize +$result | Export-Csv -Path $OutCsv -NoTypeInformation -Encoding UTF8 +Write-Host "CSV: $OutCsv" + +# ---- For each top computer, list failed updates (titles) ---- +$updScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope +foreach ($item in $result) { + $pc = $allComputers | Where-Object { $_.FullDomainName -eq $item.ComputerName } + if (-not $pc) { continue } + $failed = $pc.GetUpdateInstallationInfoPerUpdate($updScope) | + Where-Object UpdateInstallationState -EQ 'Failed' + if ($failed) { + Write-Host "`n$($item.ComputerName) — failed updates:" + foreach ($u in $failed) { ($wsus.GetUpdate($u.UpdateId).Title) | ForEach-Object { Write-Host " - $_" } } + } +} \ No newline at end of file diff --git a/report-top-error-computers/readme.md b/report-top-error-computers/readme.md new file mode 100644 index 0000000..a28b96a --- /dev/null +++ b/report-top-error-computers/readme.md @@ -0,0 +1,40 @@ +# WSUS – Display Top Error Computers (PowerShell) + +Find the **top N computers** with the most Windows Update failures in the last **N days** from WSUS, list their failed updates, and export results to CSV. + +## What the script does +- Reads WSUS **event history** over a time window. +- Aggregates errors **per computer** and shows the **Top N**. +- Prints failed **KB titles per machine**. +- Exports a CSV: `WSUS_FailedComputers_YYYYMMDD.csv`. + +## Requirements +- Run **on the WSUS server**, in an **elevated** 64-bit PowerShell. +- WSUS API available: + - `UpdateServices` module **or** + - `"%ProgramFiles%\Update Services\Tools\Microsoft.UpdateServices.Administration.dll"`. + +## Usage +Save as `Top-ErrorComputers.ps1`, then run: +```powershell +powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Top-ErrorComputers.ps1 +``` + +## Configuration +Edit the variables at the top of the script: +- `$Days` – time window (default: `7`) +- `$Top` – number of computers to display (default: `10`) +- `$OutCsv` – export path + +## Output +- Console table: `ComputerName`, `IPAddress`, `Errors`, `LastError` +- CSV file at `$OutCsv` +- For each “top” computer, a list of **failed update titles** is printed below the table. + +## Optional: schedule (Task Scheduler) +```powershell +schtasks /Create /TN "WSUS Top Error Computers" ^ + /TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Top-ErrorComputers.ps1" ^ + /SC DAILY /ST 02:00 /RU SYSTEM /RL HIGHEST /F +``` + diff --git a/reset-windows-update-agent/CleanFull.ps1 b/reset-windows-update-agent/CleanFull.ps1 new file mode 100644 index 0000000..88c628a --- /dev/null +++ b/reset-windows-update-agent/CleanFull.ps1 @@ -0,0 +1,68 @@ +# Script to stop update-related services, rename folders, and restart services + +$LogPath = "C:\Windows\Temp\WUA_Reset.log" +$Services = @("wuauserv", "cryptSvc", "bits", "msiserver") +$SoftwareDistribution = "C:\Windows\SoftwareDistribution" +$SoftwareDistributionOld = "C:\Windows\SoftwareDistribution.old" +$Catroot2 = "C:\Windows\System32\catroot2" +$Catroot2Old = "C:\Windows\System32\catroot2.old" + +function Write-Log { + param([string]$Message) + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + Add-Content -Path $LogPath -Value "$timestamp $Message" +} + +# Stop services +foreach ($svc in $Services) { + try { + Write-Log "Stopping service: $svc" + Stop-Service -Name $svc -Force -ErrorAction Stop + } catch { + Write-Log "Failed to stop service $svc: $_" + } +} + +Start-Sleep -Seconds 3 + +# Rename SoftwareDistribution folder +if (Test-Path $SoftwareDistribution) { + try { + if (Test-Path $SoftwareDistributionOld) { + Remove-Item -Path $SoftwareDistributionOld -Recurse -Force + Write-Log "Removed existing $SoftwareDistributionOld" + } + Rename-Item -Path $SoftwareDistribution -NewName "SoftwareDistribution.old" + Write-Log "Renamed $SoftwareDistribution to $SoftwareDistributionOld" + } catch { + Write-Log "Failed to rename $SoftwareDistribution: $_" + } +} + +# Rename catroot2 folder +if (Test-Path $Catroot2) { + try { + if (Test-Path $Catroot2Old) { + Remove-Item -Path $Catroot2Old -Recurse -Force + Write-Log "Removed existing $Catroot2Old" + } + Rename-Item -Path $Catroot2 -NewName "catroot2.old" + Write-Log "Renamed $Catroot2 to $Catroot2Old" + } catch { + Write-Log "Failed to rename $Catroot2: $_" + } +} + +Start-Sleep -Seconds 2 + +# Start services +foreach ($svc in $Services) { + try { + Write-Log "Starting service: $svc" + Start-Service -Name $svc -ErrorAction Stop + } catch { + Write-Log "Failed to start service $svc: $_" + } +} + +Write-Log "Script completed." diff --git a/reset-windows-update-agent/Cleanuplight.ps1 b/reset-windows-update-agent/Cleanuplight.ps1 new file mode 100644 index 0000000..73c615c --- /dev/null +++ b/reset-windows-update-agent/Cleanuplight.ps1 @@ -0,0 +1,51 @@ +$global:LogPath = "C:\Windows\Temp\Wuauserv_Cleanup.log" +$ServiceName = "wuauserv" + +function Write-Log { + param([string]$Message) + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + Add-Content -Path $global:LogPath -Value "$timestamp $Message" + write-host $Message +} + +function Clean-WUClientFolders { + Write-Log "Cleaning up Windows Update client folders" + $windir = $env:WINDIR + $WUDownload = Join-Path $windir "SoftwareDistribution\Download" + $WUDataStore = Join-Path $windir "SoftwareDistribution\Datastore" + + if (Test-Path $WUDownload) { + try { + Remove-Item $WUDownload -Recurse -Force + Write-Log "Deleted $WUDownload" + } catch { + Write-Log ("Failed to delete $WUDownload") + } + } + if (Test-Path $WUDataStore) { + try { + Remove-Item $WUDataStore -Recurse -Force + Write-Log "Deleted $WUDataStore" + } catch { + Write-Log ("Failed to delete $WUDataStore") + } + } +} + +try { + Write-Log "Stopping $ServiceName" + Stop-Service -Name $ServiceName -Force -ErrorAction Stop + Start-Sleep -Seconds 3 +} catch { + Write-Log ("Failed to stop $ServiceName") +} + +Clean-WUClientFolders + +try { + Write-Log "Starting $ServiceName" + Start-Service -Name $ServiceName -ErrorAction Stop + Write-Log "$ServiceName started" +} catch { + Write-Log ("Failed to start $ServiceName") +} diff --git a/reset-windows-update-agent/readme.md b/reset-windows-update-agent/readme.md new file mode 100644 index 0000000..af2bdd8 --- /dev/null +++ b/reset-windows-update-agent/readme.md @@ -0,0 +1,43 @@ +# Reset Windows Update Components (PowerShell) + +Two maintained scripts to fix stuck Windows Update on Windows 10/11 and Server: + +- **cleanlight.ps1** — quick cache cleanup (fast, minimal). +- **cleanFull.ps1** — full component reset (deeper, reversible). + +## What each script does +- `cleanlight.ps1` + - Stops `wuauserv` + - Deletes `%WINDIR%\SoftwareDistribution\Download` and `...\Datastore` + - Restarts `wuauserv` + - Log: `C:\Windows\Temp\Wuauserv_Cleanup.log` + +- `cleanFull.ps1` + - Stops `wuauserv`, `bits`, `cryptSvc`, `msiserver` + - Renames `%WINDIR%\SoftwareDistribution` → `SoftwareDistribution.old` + - Renames `%WINDIR%\System32\catroot2` → `catroot2.old` + - Restarts services + - Log: `C:\Windows\Temp\WUA_Reset.log` + +> Note: Both approaches reset the **local** Windows Update history view. The first scan afterward can be longer. + +## Requirements +- Run **as Administrator** on the affected device. +- Use **64-bit** PowerShell path. +- Close the Windows Update UI before running. + +## Usage +```powershell +# Light cleanup +C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\cleanlight.ps1 + +# Full reset +C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\cleanFull.ps1 +``` + +## After running +- Trigger a scan: `USOClient StartScan` (Win10/11) or wait for the next schedule. +- Optionally delete `*.old` folders after a few days if disk space matters. +- Check logs (paths above) if issues persist; see also `C:\Windows\WindowsUpdate.log` and `C:\Windows\Logs\CBS\CBS.log`. + + diff --git a/sql-maintenance/Maintenance.sql b/sql-maintenance/Maintenance.sql new file mode 100644 index 0000000..522e032 --- /dev/null +++ b/sql-maintenance/Maintenance.sql @@ -0,0 +1,118 @@ +USE SUSDB; +GO +SET NOCOUNT ON; + +-- Rebuild or reorganize indexes based on their fragmentation levels +DECLARE @work_to_do TABLE ( + objectid int + , indexid int + , pagedensity float + , fragmentation float + , numrows int +) + +DECLARE @objectid int; +DECLARE @indexid int; +DECLARE @schemaname nvarchar(130); +DECLARE @objectname nvarchar(130); +DECLARE @indexname nvarchar(130); +DECLARE @numrows int +DECLARE @density float; +DECLARE @fragmentation float; +DECLARE @command nvarchar(4000); +DECLARE @fillfactorset bit +DECLARE @numpages int + +-- Select indexes that need to be defragmented based on the following +-- * Page density is low +-- * External fragmentation is high in relation to index size +PRINT 'Estimating fragmentation: Begin. ' + convert(nvarchar, getdate(), 121) +INSERT @work_to_do +SELECT + f.object_id + , index_id + , avg_page_space_used_in_percent + , avg_fragmentation_in_percent + , record_count +FROM + sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'SAMPLED') AS f +WHERE + (f.avg_page_space_used_in_percent < 85.0 and f.avg_page_space_used_in_percent/100.0 * page_count < page_count - 1) + or (f.page_count > 50 and f.avg_fragmentation_in_percent > 15.0) + or (f.page_count > 10 and f.avg_fragmentation_in_percent > 80.0) + +PRINT 'Number of indexes to rebuild: ' + cast(@@ROWCOUNT as nvarchar(20)) + +PRINT 'Estimating fragmentation: End. ' + convert(nvarchar, getdate(), 121) + +SELECT @numpages = sum(ps.used_page_count) +FROM + @work_to_do AS fi + INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id + INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id + +-- Declare the cursor for the list of indexes to be processed. +DECLARE curIndexes CURSOR FOR SELECT * FROM @work_to_do + +-- Open the cursor. +OPEN curIndexes + +-- Loop through the indexes +WHILE (1=1) +BEGIN + FETCH NEXT FROM curIndexes + INTO @objectid, @indexid, @density, @fragmentation, @numrows; + IF @@FETCH_STATUS < 0 BREAK; + + SELECT + @objectname = QUOTENAME(o.name) + , @schemaname = QUOTENAME(s.name) + FROM + sys.objects AS o + INNER JOIN sys.schemas as s ON s.schema_id = o.schema_id + WHERE + o.object_id = @objectid; + + SELECT + @indexname = QUOTENAME(name) + , @fillfactorset = CASE fill_factor WHEN 0 THEN 0 ELSE 1 END + FROM + sys.indexes + WHERE + object_id = @objectid AND index_id = @indexid; + + IF ((@density BETWEEN 75.0 AND 85.0) AND @fillfactorset = 1) OR (@fragmentation < 30.0) + SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE'; + ELSE IF @numrows >= 5000 AND @fillfactorset = 0 + SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD WITH (FILLFACTOR = 90)'; + ELSE + SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD'; + PRINT convert(nvarchar, getdate(), 121) + N' Executing: ' + @command; + EXEC (@command); + PRINT convert(nvarchar, getdate(), 121) + N' Done.'; +END + +-- Close and deallocate the cursor. +CLOSE curIndexes; +DEALLOCATE curIndexes; + + +IF EXISTS (SELECT * FROM @work_to_do) +BEGIN + PRINT 'Estimated number of pages in fragmented indexes: ' + cast(@numpages as nvarchar(20)) + SELECT @numpages = @numpages - sum(ps.used_page_count) + FROM + @work_to_do AS fi + INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id + INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id + + PRINT 'Estimated number of pages freed: ' + cast(@numpages as nvarchar(20)) +END +GO + + +--Update all statistics +PRINT 'Updating all statistics.' + convert(nvarchar, getdate(), 121) +EXEC sp_updatestats +PRINT 'Done updating statistics.' + convert(nvarchar, getdate(), 121) +GO \ No newline at end of file diff --git a/sql-maintenance/readme.md b/sql-maintenance/readme.md new file mode 100644 index 0000000..ac7936c --- /dev/null +++ b/sql-maintenance/readme.md @@ -0,0 +1,38 @@ +# WSUS SUSDB Maintenance (Reindex + Update Stats) + +Keep **SUSDB** fast: rebuild/reorganize fragmented indexes, then run `sp_updatestats`. Run off-hours; back up first. + +## Requirements +- Admin on the WSUS server. +- Either **SqlServer** PowerShell module (`Install-Module SqlServer`) or **sqlcmd** tools. +- WID instance uses the named pipe: `np:\\.\pipe\MICROSOFT##WID\tsql\query`. + +## Quick start +1) Save the SQL script as: `C:\Scripts\WSUSDBMaintenance.sql` (same as in this repo/article). +2) Run one of the following: + +```powershell +# PowerShell (SqlServer module) — SQL Server instance +Invoke-Sqlcmd -ServerInstance 'localhost' -Database 'SUSDB' ` + -InputFile C:\Scripts\WSUSDBMaintenance.sql -AbortOnError + +# PowerShell (SqlServer module) — WID (local only) +Invoke-Sqlcmd -ServerInstance 'np:\\.\pipe\MICROSOFT##WID\tsql\query' ` + -Database 'SUSDB' -InputFile C:\Scripts\WSUSDBMaintenance.sql -AbortOnError +``` + +```powershell +# sqlcmd CLI — SQL Server +sqlcmd -S localhost -d SUSDB -i C:\Scripts\WSUSDBMaintenance.sql -b + +# sqlcmd CLI — WID (local only) +sqlcmd -S np:\\.\pipe\MICROSOFT##WID\tsql\query -d SUSDB -i C:\Scripts\WSUSDBMaintenance.sql -b +``` + +## Schedule (optional) +```powershell +schtasks /Create /TN "WSUS DB Maintenance" ^ + /TR "powershell.exe -NoProfile -Command Invoke-Sqlcmd -ServerInstance 'np:\\.\pipe\MICROSOFT##WID\tsql\query' -Database SUSDB -InputFile C:\Scripts\WSUSDBMaintenance.sql -AbortOnError" ^ + /SC MONTHLY /D 1 /ST 02:00 /RU "SYSTEM" /RL HIGHEST /F +``` + diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSGetModuleInfo.xml b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSGetModuleInfo.xml new file mode 100644 index 0000000..4890244 Binary files /dev/null and b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSGetModuleInfo.xml differ diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWUSettings.xml.tmp b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWUSettings.xml.tmp new file mode 100644 index 0000000..f7a9459 Binary files /dev/null and b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWUSettings.xml.tmp differ diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.Format.ps1xml b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.Format.ps1xml new file mode 100644 index 0000000..7642280 --- /dev/null +++ b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.Format.ps1xml @@ -0,0 +1,616 @@ + + + + + PSWindowsUpdate + + PSWindowsUpdate.WindowsUpdate + + + + + 12 + + + 10 + + + 9 + + + Right + 6 + + + + + + + + ComputerName + + + Status + + + KB + + + Size + + + Title + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.OfflineMSU + + + + + 1 + + + 10 + + + + 11 + + + Right + 8 + + + + + + + X + + + Result + + + Title + + + LastUpdated + + + Size + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.WindowsUpdateJob + + + + + 1 + + + 12 + + + 10 + + + 9 + + + Right + 6 + + + + + + + + X + + + ComputerName + + + Result + + + KB + + + Size + + + Title + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.History + + + + + 12 + + + 14 + + + 10 + + + 19 + + + + + + + + ComputerName + + + Operationname + + + Result + + + Date + + + Title + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.ServiceManager + + + + + 36 + + + 9 + + + + 9 + + + + + + + + ServiceID + + + IsManaged + + + IsDefaultAUService + + + Name + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.AgentInfo + + + + + 12 + + + 15 + + + 15 + + + 10 + + + + + + + + ComputerName + + + PSWindowsUpdate + + + PSWUModuleDll + + + ApiVersion + + + WuapiDllVersion + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.InstallerStatus + + + + + 12 + + + + + + + + ComputerName + + + IsBusy + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.LastResults + + + + + 12 + + + 10 + + + + + + + + ComputerName + + + LastSearchSuccessDate + + + LastInstallationSuccessDate + + + + + + + + PSWindowsUpdate + + PSWindowsUpdate.WUJob + + + + + 12 + + + 20 + + + + + + + + + + ComputerName + + + Name + + + + $_.Definition.Actions[1].Arguments -replace '-Command "|"$' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll new file mode 100644 index 0000000..1afc87f Binary files /dev/null and b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll differ diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll-Help.xml b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll-Help.xml new file mode 100644 index 0000000..de42ff6 --- /dev/null +++ b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.dll-Help.xml @@ -0,0 +1,10653 @@ + + + + + + Set-PSWUSettings + Set + PSWUSettings + + Save PSWUSettings. + + + + Use Set-PSWUSettings save PSWindowsUpdate module settings to XML file. + + + + + Set-PSWUSettings + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Properties + + Alternative report message propertie.s + + string + + System.String + + + + + + SaveAsSystem + + Invoke-WUJob to save credential as system user + + string + + System.String + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SmtpCredential + + Save smtp credential to Credential Manager. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + SmtpEnableSsl + + Save enable ssl to PSWUSettings file. + + bool + + System.Boolean + + + False + + + + SmtpFrom + + Save smtp sernder to PSWUSettings file. + + string + + System.String + + + + + + SmtpPort + + Save smtp port to PSWUSettings file. + + int + + System.Int32 + + + 25 + + + + SmtpServer + + Save smtp server to PSWUSettings file. + + string + + System.String + + + + + + SmtpSubject + + Save alternative message subject to PSWUSettings file. + + string + + System.String + + + + + + SmtpTo + + Save smtp recipient to PSWUSettings file. + + string + + System.String + + + + + + Style + + Alternative report message format style. + + string + + System.String + + + + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SmtpServer + + Save smtp server to PSWUSettings file. + + string + + System.String + + + + + + SmtpPort + + Save smtp port to PSWUSettings file. + + int + + System.Int32 + + + 25 + + + + SmtpEnableSsl + + Save enable ssl to PSWUSettings file. + + bool + + System.Boolean + + + False + + + + SmtpCredential + + Save smtp credential to Credential Manager. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + SmtpTo + + Save smtp recipient to PSWUSettings file. + + string + + System.String + + + + + + SmtpFrom + + Save smtp sernder to PSWUSettings file. + + string + + System.String + + + + + + SmtpSubject + + Save alternative message subject to PSWUSettings file. + + string + + System.String + + + + + + Properties + + Alternative report message propertie.s + + string + + System.String + + + + + + Style + + Alternative report message format style. + + string + + System.String + + + + + + SaveAsSystem + + Invoke-WUJob to save credential as system user + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ---------- EXAMPLE 1 ---------- + Set Office 365 as smtp server for PSWindowsUpdate module. + +Set-PSWUSettings -SmtpServer smtp.office365.com -SmtpPort 587 -SmtpEnableSsl $true -SmtpSubject "PSWindowsUpdate Report" -SmtpTo mgajda@psmvp.pl -SmtpFrom mgajda@psmvp.pl -SmtpCredential (Get-Credential mgajda@psmvp.pl) + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WindowsUpdate + Get + WindowsUpdate + + Get list of available updates meeting the criteria. + + + + Use Get-WindowsUpdate (aka Get-WUList) cmdlet to get list of available or installed updates meeting specific criteria. + Use Download-WindowsUpdate alias to get list of updates and download it. Equivalent Get-WindowsUpdate -Download. + Use Install-WindowsUpdate (aka Get-WUInstall) alias to get list of updates and install it. Equivalent Get-WindowsUpdate -Install. + Use Hide-WindowsUpdate alias to get list of updates and hide it. Equivalent Get-WindowsUpdate -Hide. + Use Show-WindowsUpdate (aka UnHide-WindowsUpdate) alias to get list of updates and unhide it. Equivalent Get-WindowsUpdate -Hide:$false. + There are two types of filtering update: Pre search criteria, Post search criteria. + - Pre search works on server side, like example: (IsInstalled = 0 and IsHidden = 0 and CategoryIds contains '0fa1201d-4330-4fa8-8ae9-b877473b6441' ) + - Post search work on client side after get the pre-filtered list of updates, like example $KBArticleID -match $Update.KBArticleIDs + Status info list:\r\n[A|R]DIMHUB\r\nA-IsAccetped\r\nR-IsRejected\r\n D-IsDownloaded\r\n F-DownloadFailed\r\n ?-IsInvoked\r\n I-IsInstalled\r\n F-InstallFailed\r\n ?-IsInvoked\r\n R-RebootRequired\r\n M-IsMandatory\r\n H-IsHidden\r\n U-IsUninstallable\r\n B-IsBeta + + + + + Get-WindowsUpdate + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + RootCategories + + Post search criteria. Finds updates that contain a specified root category name 'Critical Updates', 'Definition Updates', 'Drivers', 'Feature Packs', 'Security Updates', 'Service Packs', 'Tools', 'Update Rollups', 'Updates', 'Upgrades', 'Microsoft'. + + string[] + + System.String[] + + + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ServiceID + + Use specific Service Manager if it's available. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WindowsUpdate + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + RootCategories + + Post search criteria. Finds updates that contain a specified root category name 'Critical Updates', 'Definition Updates', 'Drivers', 'Feature Packs', 'Security Updates', 'Service Packs', 'Tools', 'Update Rollups', 'Updates', 'Upgrades', 'Microsoft'. + + string[] + + System.String[] + + + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WindowsUpdate + + Use Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WindowsUpdate + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MicrosoftUpdate + + Use Windows Update Service Manager - '9482f4b4-e343-43b6-b170-9a65bc822c77' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + RootCategories + + Post search criteria. Finds updates that contain a specified root category name 'Critical Updates', 'Definition Updates', 'Drivers', 'Feature Packs', 'Security Updates', 'Service Packs', 'Tools', 'Update Rollups', 'Updates', 'Upgrades', 'Microsoft'. + + string[] + + System.String[] + + + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ServiceID + + Use specific Service Manager if it's available. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + WindowsUpdate + + Use Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MicrosoftUpdate + + Use Windows Update Service Manager - '9482f4b4-e343-43b6-b170-9a65bc822c77' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RootCategories + + Post search criteria. Finds updates that contain a specified root category name 'Critical Updates', 'Definition Updates', 'Drivers', 'Feature Packs', 'Security Updates', 'Service Packs', 'Tools', 'Update Rollups', 'Updates', 'Upgrades', 'Microsoft'. + + string[] + + System.String[] + + + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + Silent + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + This is an alias of the IgnoreUserInput parameter. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + + + + + + + PSWindowsUpdate.WindowsUpdate + + + + OutputType for WindowsUpdate objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get windows updates available from default service manager. + +Get-WindowsUpdate -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------- KB890830 44MB Narzędzie Windows do usuwania złośliwego oprogramowania dla systemów Window... +MG-PC ------- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... +MG-PC ------- KB4034662 21MB 2017-08 Aktualizacja zabezpieczeń Adobe Flash Player w Windows 10 Version 1... +MG-PC ------- KB4035631 11MB 2017-08 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... + + + ---------- EXAMPLE 2 ---------- + Get all installed drivers that are available at Windows Update. Additionaly show pre search criteria. + +Get-WindowsUpdate -WindowsUpdate -UpdateType Driver -IsInstalled -ShowPreSearchCriteria -Verbose + +PreSearchCriteria: IsInstalled = 0 and Type = 'Driver' and IsHidden = 0 +VERBOSE: MG-PC: Connecting to Windows Update server.Please wait... +VERBOSE: Found[1] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MGAJDALAP3 -DI---- 3MB Intel - Other hardware - Intel(R) Watchdog Timer Driver (Intel(R) WDT) + + + ---------- EXAMPLE 3 ---------- + Get all available update on remote machine MG-PC, that contains in Title this two words 'Aktualizacja' and 'Windows 10' (as regular expression). + +Get-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -Title "Aktualizacja.*Windows 10" -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[14] Updates in pre search criteria +VERBOSE: Found[5] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------- KB3150513 2MB 2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... +MG-PC ------- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... +MG-PC ------- KB4034662 21MB 2017-08 Aktualizacja zabezpieczeń Adobe Flash Player w Windows 10 Version 1... +MG-PC ------- KB4035631 11MB 2017-08 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... +MG-PC ------- KB4033637 4MB Aktualizacja systemu Windows 10 Version 1607 dla komputerów z procesorami x... + + + ---------- EXAMPLE 4 ---------- + Hide update with KBArticleID: KB4034658. + +Get-WindowsUpdate -KBArticleID KB4034658 -Hide -Verbose +or use alias +Hide-WindowsUpdate -KBArticleID KB4034658 -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Hide 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB4034658)[1GB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ---H-- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... + + + ---------- EXAMPLE 5 ---------- + Unhide update with KBArticleID: KB4034658. + +Get-WindowsUpdate -KBArticleID KB4034658 -WithHidden -Hide:$false -Verbose +or use alias +Show-WindowsUpdate -KBArticleID KB4034658 -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Show 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB4034658)[1GB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------ KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... + + + ---------- EXAMPLE 6 ---------- + Schedule job at 6:00 PM to install update with UpdateId='ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber=200. Update will be automaticaly accepted and after all serwer will be automaticaly restarted if needed. + +Get-WindowsUpdate -MicrosoftUpdate -UpdateID ddb74579-7a1f-4d1f-80c8-e8647055314e -RevisionNumber 200 -ScheduleJob (Get-Date -Hour 18 -Minute 0 -Second 0) -Install -AcceptAll -AutoReboot -Verbose +or use alias +Install-WindowsUpdate -MicrosoftUpdate -UpdateID ddb74579-7a1f-4d1f-80c8-e8647055314e -RevisionNumber 200 -ScheduleJob (Get-Date -Hour 18 -Minute 0 -Second 0) -AcceptAll -AutoReboot -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[1] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria +VERBOSE: Choosed pre Search Criteria: (UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200) + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB4023307 13MB Microsoft Silverlight(KB4023307) +VERBOSE: Accepted[1] Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC(31.08.2017 18:00:00): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200)\" -AcceptAll -AutoReboot -Download -Install -MicrosoftUpdate -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" + + + ---------- EXAMPLE 7 ---------- + Install updates on remote computer. After all send a report from the installation process. + +Install-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -AcceptAll -AutoReboot -SendReport -PSWUSettings @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} -Verbose +or use global PSWUSettings +@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} | Export-Clixml -Path 'C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\PSWUSettings.xml' +Install-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -AcceptAll -AutoReboot -SendReport -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Microsoft Silverlight (KB4023307)[13MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +Confirm +Are you sure you want to perform this action? +Performing the operation "2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB3150513)[2MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +Confirm +Are you sure you want to perform this action? +Performing the operation "Aktualizacja pakietu językowego usługi Microsoft Dynamics 365 2.1[47MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): L + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB4023307 13MB Microsoft Silverlight (KB4023307) +1 MG-PC Accepted KB3150513 2MB 2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na arc... +1 MG-PC Rejected KB4013759 47MB Aktualizacja pakietu językowego usługi Microsoft Dynamics 365 2.1 +1 MG-PC Rejected KB3186568 67MB Program Microsoft .NET Framework 4.7 w syst. Windows 10 Version 1607 i Wi... +VERBOSE: Accepted [2] +Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC (Now): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200) or (UpdateID = '151c4402-513c-4f39-8da1-f84d0956b5e3' and RevisionNumber = 200)\" -AcceptAll -Download -Install -AutoReboot -MicrosoftUpdate -SendReport -ProofOfLife -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" + + + ---------- EXAMPLE 8 ---------- + Schedule Job to install all available updates and automatically reboot system if needed. Also send report after installation (but before reboot if needed) and send second instalation history report after reboot. + +@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} | Export-Clixml -Path 'C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\PSWUSettings.xml' +Install-WindowsUpdate -MicrosoftUpdate -SendReport -SendHistory -AcceptAll -AutoReboot -ScheduleJob (Get-Date -Hour 18 -Minute 30 -Second 0) -ComputerName MG-PC -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB3038936 5MB Aktualizacja systemu Windows 8.1 dla komputerów z procesorami x64(KB3038... +1 MG-PC Accepted KB3186606 4MB Pakiety językowe programu Microsoft.NET Framework 4.7 w syst. Windows 8.... +1 MG-PC Accepted KB4035038 53MB Sierpień 2017: wersja zapozn. pak.zb.aktual.jakości dla pr. .NET Frame... +1 MG-PC Accepted KB2267602 309MB Aktualizacja definicji dla: Windows Defender — KB2267602 (Definicja 1.251... +VERBOSE: Accepted[4] Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC (02.09.2017 08:30:00): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'e69c9679-7ce8-489a-a21c-62fb920be67a' and RevisionNumber = 201) or(UpdateID = 'de44604d-ec38-4a7f-ac63-28b3edfdb382' and RevisionNumber = 207) or(UpdateID = '9cf1d8c9-a7c3-4603-90e8-f22131ff6d7e' and RevisionNumber = 201) or(UpdateID = 'b51935f9-0e40-4624-9c26-b29bff92dcf9' and RevisionNumber = 200)\" -AcceptAll -Install -AutoReboot -MicrosoftUpdate -SendReport -SendHistory -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" +VERBOSE: Send report + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Remove-WindowsUpdate + Remove + WindowsUpdate + + Uninstall update. + + + + Use Remove-WindowsUpdate to uninstall update. + + + + + Remove-WindowsUpdate + + + KBArticleID + + KBArticleID that will be uninstalled. + + string + + System.String + + + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleJob + + Specify schedule time job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + WUSAMode + + Wse wusa.exe instead of WU Api. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Remove-WindowsUpdate + + + UpdateID + + Update ID that will be uninstalled. + + string + + System.String + + + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleJob + + Specify schedule time job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + WUSAMode + + Wse wusa.exe instead of WU Api. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + ScheduleJob + + Specify schedule time job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + KBArticleID + + KBArticleID that will be uninstalled. + + string + + System.String + + + + + HotFixID + + KBArticleID that will be uninstalled. + This is an alias of the KBArticleID parameter. + + string + + System.String + + + + + + UpdateID + + Update ID that will be uninstalled. + + string + + System.String + + + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + WUSAMode + + Wse wusa.exe instead of WU Api. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + ---------- EXAMPLE 1 ---------- + Try to uninstall update with specific KBArticleID = KB958830. + +Get-WUUninstall -KBArticleID KB958830 + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WindowsUpdate_v2 + Get + WindowsUpdate_v2 + + Get list of available updates meeting the criteria. + + + + Use Get-WindowsUpdate (aka Get-WUList) cmdlet to get list of available or installed updates meeting specific criteria. + Use Download-WindowsUpdate alias to get list of updates and download it. Equivalent Get-WindowsUpdate -Download. + Use Install-WindowsUpdate (aka Get-WUInstall) alias to get list of updates and install it. Equivalent Get-WindowsUpdate -Install. + Use Hide-WindowsUpdate alias to get list of updates and hide it. Equivalent Get-WindowsUpdate -Hide. + Use Show-WindowsUpdate (aka UnHide-WindowsUpdate) alias to get list of updates and unhide it. Equivalent Get-WindowsUpdate -Hide:$false. + There are two types of filtering update: Pre search criteria, Post search criteria. + - Pre search works on server side, like example: (IsInstalled = 0 and IsHidden = 0 and CategoryIds contains '0fa1201d-4330-4fa8-8ae9-b877473b6441' ) + - Post search work on client side after get the pre-filtered list of updates, like example $KBArticleID -match $Update.KBArticleIDs + Status info list:\r\n[A|R]DIMHUB\r\nA-IsAccetped\r\nR-IsRejected\r\n D-IsDownloaded\r\n F-DownloadFailed\r\n ?-IsInvoked\r\n I-IsInstalled\r\n F-InstallFailed\r\n ?-IsInvoked\r\n R-RebootRequired\r\n M-IsMandatory\r\n H-IsHidden\r\n U-IsUninstallable\r\n B-IsBeta + + + + + Get-WindowsUpdate_v2 + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ServiceID + + Use specific Service Manager if it's available. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WindowsUpdate_v2 + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WindowsUpdate + + Use Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WindowsUpdate_v2 + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MicrosoftUpdate + + Use Windows Update Service Manager - '9482f4b4-e343-43b6-b170-9a65bc822c77' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file (more preferred) in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendHistory + + Send install history (Get-WUHistory) report after successful update installation or system startup. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleJob + + Specify time when job will start. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + AcceptAll + + Do not ask confirmation for updates. Download or Install all available updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RecurseCycle + + Specify number of cycles for check updates after successful update installation or system startup. First run is always main cycle (-RecurseCycle 1 or none). Second (-RecurseCycle 2) and n (-RecurseCycle n) cycle are recursive. + + int + + System.Int32 + + + 0 + + + + Hide + + Get list of updates and hide/unhide approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Download + + Get list of updates and download approved updates, but do not install it. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceDownload + + Forces the download of updates that are already installed or that cannot be installed. Works only with -Download. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Install + + Get list of updates and install approved updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ForceInstall + + A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already installed. Before you use ForceInstall to force an installation, determine whether the update is installed and available. If an update is not installed, a forced installation fails. Works only with -Install. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreReboot + + Do not ask for reboot if it needed, but do not reboot automaticaly. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleReboot + + Specify time when system will be rebooted. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ServiceID + + Use specific Service Manager if it's available. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + WindowsUpdate + + Use Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MicrosoftUpdate + + Use Windows Update Service Manager - '9482f4b4-e343-43b6-b170-9a65bc822c77' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Criteria + + Pre search criteria - native for WUAPI. Set own string that specifies the search criteria. https://docs.microsoft.com/pl-pl/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-search + + string + + System.String + + + + + + UpdateType + + Pre search criteria - native for WUAPI. Finds updates with a specific type, such as 'Driver' and 'Software'. Default value contains all updates. + + string + + System.String + + + + + + DeploymentAction + + Pre search criteria - native for WUAPI. Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + "DeploymentAction='Uninstallation'" finds updates that are deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. + If this criterion is not explicitly specified, each group of criteria that is joined to an AND operator implies "DeploymentAction='Installation'". + + string + + System.String + + + + + + IsAssigned + + Pre search criteria - native for WUAPI. Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by Automatic Updates, which depends on the other query criteria.At most, one assigned Windows-based driver update is returned for each local device on a destination computer. + "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsPresent + + Pre search criteria - native for WUAPI. When set to 1, finds updates that are present on a computer. + "IsPresent=1" finds updates that are present on a destination computer.If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + "IsPresent=0" finds updates that are not installed for any product on a destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + BrowseOnly + + Pre search criteria - native for WUAPI. "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnWebSites + + Pre search criteria - native for WUAPI. Finds updates where the AutoSelectOnWebSites property has the specified value. + "AutoSelectOnWebSites=1" finds updates that are flagged to be automatically selected by Windows Update. + "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + UpdateID + + Pre search criteria - native for WUAPI. Finds updates with a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + NotUpdateID + + Pre search criteria - native for WUAPI. Finds updates without a specific UUID (or sets of UUIDs), such as '12345678-9abc-def0-1234-56789abcdef0'. + + string[] + + System.String[] + + + + + + RevisionNumber + + Pre search criteria - native for WUAPI. Finds updates with a specific RevisionNumber, such as '100'. This criterion must be combined with the UpdateID param. + + int + + System.Int32 + + + 0 + + + + CategoryIDs + + Pre search criteria - native for WUAPI. Finds updates that belong to a specified category (or sets of UUIDs), such as '0fa1201d-4330-4fa8-8ae9-b877473b6441'. + + string[] + + System.String[] + + + + + + IsInstalled + + Pre search criteria - native for WUAPI. Finds updates that are installed on the destination computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IsHidden + + Pre search criteria - native for WUAPI. Finds updates that are marked as hidden on the destination computer. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WithHidden + + Pre search criteria - native for WUAPI. Finds updates that are both hidden and not on the destination computer. Overwrite IsHidden param. Default search criteria is only not hidden upadates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ShowPreSearchCriteria + + Show choosen search criteria. Only works for pre search criteria. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Category + + Post search criteria. Finds updates that contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + KBArticleID + + Post search criteria. Finds updates that contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + Title + + Post search criteria. Finds updates that match part of title (case sensitive), such as '.NET Framework 4'. + + string + + System.String + + + + + + Severity + + Post search criteria. Finds updates that match part of severity, such as 'Important', 'Critical', 'Moderate', etc... + + string[] + + System.String[] + + + + + + NotCategory + + Post search criteria. Finds updates that not contain a specified category name (or sets of categories name), such as 'Updates', 'Security Updates', 'Critical Updates', etc... + + string[] + + System.String[] + + + + + + NotKBArticleID + + Post search criteria. Finds updates that not contain a KBArticleID (or sets of KBArticleIDs), such as 'KB982861'. + + string[] + + System.String[] + + + + + + NotTitle + + Post search criteria. Finds updates that not match part of title (case sensitive). + + string + + System.String + + + + + + NotSeverity + + Post search criteria. Finds updates that not match part of severity. + + string[] + + System.String[] + + + + + + IgnoreUserInput + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + Silent + + Post search criteria. Finds updates that the installation or uninstallation of an update can't prompt for user input. + This is an alias of the IgnoreUserInput parameter. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IgnoreRebootRequired + + Post search criteria. Finds updates that specifies the restart behavior that not occurs when you install or uninstall the update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoSelectOnly + + Install only the updates that have status AutoSelectOnWebsites on true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + MaxSize + + Post search criteria. Finds updates that have MaxDownloadSize less or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + MinSize + + Post search criteria. Finds updates that have MaxDownloadSize greater or equal. Size is in Bytes. + + long + + System.Int64 + + + 0 + + + + Debuger + + Debuger return original exceptions. For additional debug information use $DebugPreference = "Continue" + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. Interactive remote connection works only for checking updates. For download or install cmdlet creates an Invoke-WUJob task. + + + + + + + + PSWindowsUpdate.WindowsUpdate + + + + OutputType for WindowsUpdate objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get windows updates available from default service manager. + +Get-WindowsUpdate -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------- KB890830 44MB Narzędzie Windows do usuwania złośliwego oprogramowania dla systemów Window... +MG-PC ------- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... +MG-PC ------- KB4034662 21MB 2017-08 Aktualizacja zabezpieczeń Adobe Flash Player w Windows 10 Version 1... +MG-PC ------- KB4035631 11MB 2017-08 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... + + + ---------- EXAMPLE 2 ---------- + Get all installed drivers that are available at Windows Update. Additionaly show pre search criteria. + +Get-WindowsUpdate -WindowsUpdate -UpdateType Driver -IsInstalled -ShowPreSearchCriteria -Verbose + +PreSearchCriteria: IsInstalled = 0 and Type = 'Driver' and IsHidden = 0 +VERBOSE: MG-PC: Connecting to Windows Update server.Please wait... +VERBOSE: Found[1] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MGAJDALAP3 -DI---- 3MB Intel - Other hardware - Intel(R) Watchdog Timer Driver (Intel(R) WDT) + + + ---------- EXAMPLE 3 ---------- + Get all available update on remote machine MG-PC, that contains in Title this two words 'Aktualizacja' and 'Windows 10' (as regular expression). + +Get-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -Title "Aktualizacja.*Windows 10" -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[14] Updates in pre search criteria +VERBOSE: Found[5] Updates in post search criteria + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------- KB3150513 2MB 2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... +MG-PC ------- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... +MG-PC ------- KB4034662 21MB 2017-08 Aktualizacja zabezpieczeń Adobe Flash Player w Windows 10 Version 1... +MG-PC ------- KB4035631 11MB 2017-08 Aktualizacja Windows 10 Version 1607 dla systemów opartych na archi... +MG-PC ------- KB4033637 4MB Aktualizacja systemu Windows 10 Version 1607 dla komputerów z procesorami x... + + + ---------- EXAMPLE 4 ---------- + Hide update with KBArticleID: KB4034658. + +Get-WindowsUpdate -KBArticleID KB4034658 -Hide -Verbose +or use alias +Hide-WindowsUpdate -KBArticleID KB4034658 -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Hide 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB4034658)[1GB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ---H-- KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... + + + ---------- EXAMPLE 5 ---------- + Unhide update with KBArticleID: KB4034658. + +Get-WindowsUpdate -KBArticleID KB4034658 -WithHidden -Hide:$false -Verbose +or use alias +Show-WindowsUpdate -KBArticleID KB4034658 -Verbose + +VERBOSE: MG-PC: Connecting to Windows Server Update Service server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Show 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB4034658)[1GB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ComputerName Status KB Size Title +------------ ------ -- ---- ----- +MG-PC ------ KB4034658 1GB 2017-08 Aktualizacja zbiorcza dla systemu Windows 10 Version 1607 dla syste... + + + ---------- EXAMPLE 6 ---------- + Schedule job at 6:00 PM to install update with UpdateId='ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber=200. Update will be automaticaly accepted and after all serwer will be automaticaly restarted if needed. + +Get-WindowsUpdate -MicrosoftUpdate -UpdateID ddb74579-7a1f-4d1f-80c8-e8647055314e -RevisionNumber 200 -ScheduleJob (Get-Date -Hour 18 -Minute 0 -Second 0) -Install -AcceptAll -AutoReboot -Verbose +or use alias +Install-WindowsUpdate -MicrosoftUpdate -UpdateID ddb74579-7a1f-4d1f-80c8-e8647055314e -RevisionNumber 200 -ScheduleJob (Get-Date -Hour 18 -Minute 0 -Second 0) -AcceptAll -AutoReboot -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[1] Updates in pre search criteria +VERBOSE: Found[1] Updates in post search criteria +VERBOSE: Choosed pre Search Criteria: (UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200) + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB4023307 13MB Microsoft Silverlight(KB4023307) +VERBOSE: Accepted[1] Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC(31.08.2017 18:00:00): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200)\" -AcceptAll -AutoReboot -Download -Install -MicrosoftUpdate -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" + + + ---------- EXAMPLE 7 ---------- + Install updates on remote computer. After all send a report from the installation process. + +Install-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -AcceptAll -AutoReboot -SendReport -PSWUSettings @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} -Verbose +or use global PSWUSettings +@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} | Export-Clixml -Path 'C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\PSWUSettings.xml' +Install-WindowsUpdate -ComputerName MG-PC -MicrosoftUpdate -AcceptAll -AutoReboot -SendReport -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +Confirm +Are you sure you want to perform this action? +Performing the operation "Microsoft Silverlight (KB4023307)[13MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +Confirm +Are you sure you want to perform this action? +Performing the operation "2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na architekturze x64 (KB3150513)[2MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +Confirm +Are you sure you want to perform this action? +Performing the operation "Aktualizacja pakietu językowego usługi Microsoft Dynamics 365 2.1[47MB]" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): L + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB4023307 13MB Microsoft Silverlight (KB4023307) +1 MG-PC Accepted KB3150513 2MB 2017-06 Aktualizacja Windows 10 Version 1607 dla systemów opartych na arc... +1 MG-PC Rejected KB4013759 47MB Aktualizacja pakietu językowego usługi Microsoft Dynamics 365 2.1 +1 MG-PC Rejected KB3186568 67MB Program Microsoft .NET Framework 4.7 w syst. Windows 10 Version 1607 i Wi... +VERBOSE: Accepted [2] +Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC (Now): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'ddb74579-7a1f-4d1f-80c8-e8647055314e' and RevisionNumber = 200) or (UpdateID = '151c4402-513c-4f39-8da1-f84d0956b5e3' and RevisionNumber = 200)\" -AcceptAll -Download -Install -AutoReboot -MicrosoftUpdate -SendReport -ProofOfLife -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" + + + ---------- EXAMPLE 8 ---------- + Schedule Job to install all available updates and automatically reboot system if needed. Also send report after installation (but before reboot if needed) and send second instalation history report after reboot. + +@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";Port=25} | Export-Clixml -Path 'C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\PSWUSettings.xml' +Install-WindowsUpdate -MicrosoftUpdate -SendReport -SendHistory -AcceptAll -AutoReboot -ScheduleJob (Get-Date -Hour 18 -Minute 30 -Second 0) -ComputerName MG-PC -Verbose + +VERBOSE: MG-PC: Connecting to Microsoft Update server. Please wait... +VERBOSE: Found[4] Updates in pre search criteria +VERBOSE: Found[4] Updates in post search criteria + +X ComputerName Result KB Size Title +- ------------ ------ -- ---- ----- +1 MG-PC Accepted KB3038936 5MB Aktualizacja systemu Windows 8.1 dla komputerów z procesorami x64(KB3038... +1 MG-PC Accepted KB3186606 4MB Pakiety językowe programu Microsoft.NET Framework 4.7 w syst. Windows 8.... +1 MG-PC Accepted KB4035038 53MB Sierpień 2017: wersja zapozn. pak.zb.aktual.jakości dla pr. .NET Frame... +1 MG-PC Accepted KB2267602 309MB Aktualizacja definicji dla: Windows Defender — KB2267602 (Definicja 1.251... +VERBOSE: Accepted[4] Updates ready to Download +VERBOSE: Invoke-WUJob: MG-PC (02.09.2017 08:30:00): +VERBOSE: powershell.exe -Command "Get-WindowsUpdate -Criteria \"(UpdateID = 'e69c9679-7ce8-489a-a21c-62fb920be67a' and RevisionNumber = 201) or(UpdateID = 'de44604d-ec38-4a7f-ac63-28b3edfdb382' and RevisionNumber = 207) or(UpdateID = '9cf1d8c9-a7c3-4603-90e8-f22131ff6d7e' and RevisionNumber = 201) or(UpdateID = 'b51935f9-0e40-4624-9c26-b29bff92dcf9' and RevisionNumber = 200)\" -AcceptAll -Install -AutoReboot -MicrosoftUpdate -SendReport -SendHistory -Verbose *>&1 | Out-File $Env:TEMP\PSWindowsUpdate.log" +VERBOSE: Send report + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUApiVersion + Get + WUApiVersion + + Get Windows Update Agent version. + + + + Use Get-WUAPIVersion cmdlet to get Windows Update Agent version. + + + + + Get-WUApiVersion + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.AgentInfo + + + + OutputType for AgentInfo objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get Windows Update Agent version. + +Get-WUAPIVersion + +ComputerName PSWindowsUpdate ApiVersion WuapiDllVersion +------------ --------------- ---------- --------------- +MG-PC 2.0 8.0 10.0.14393.1670 + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Reset-WUComponents + Reset + WUComponents + + Reset Windows Update components. + + + + Use Reset-WUComponents cmdlet to reset all Windows Update components to default. + + + + + Reset-WUComponents + + + + + + + + ---------- EXAMPLE 1 ---------- + Reset Windows Update components to default. + + Reset-WUComponents -Verbose + Step 1: Stop Windows Update services +VERBOSE: Background Intelligent Transfer Service(BITS) +VERBOSE: Windows Update(wuauserv) +VERBOSE: Application Identity(appidsvc) +VERBOSE: Cryptographic Services(cryptsvc) +Step 2: Delete the qmgr*.dat files +Step 3: Backup softare distribution folders +VERBOSE: Renaming Software Distribution folder to C:\WINDOWS\SoftwareDistribution.bak5 +VERBOSE: Renaming CatRoot folder to C:\WINDOWS\System32\Catroot2.bak1 +Step 4: Remove old Windows Update logs +VERBOSE: Deleting the C:\WINDOWS\WindowsUpdate.log files. +Step 5: Reset Windows Update services +VERBOSE: Reset BITS service +VERBOSE: Reset Windows Update service +Step 6: Reregister dll's +VERBOSE: regsvr32.exe / s atl.dll +VERBOSE: regsvr32.exe / s urlmon.dll +VERBOSE: regsvr32.exe / s mshtml.dll +VERBOSE: regsvr32.exe / s shdocvw.dll +VERBOSE: regsvr32.exe / s browseui.dll +VERBOSE: regsvr32.exe / s jscript.dll +VERBOSE: regsvr32.exe / s vbscript.dll +VERBOSE: regsvr32.exe / s scrrun.dll +VERBOSE: regsvr32.exe / s msxml.dll +VERBOSE: regsvr32.exe / s msxml3.dll +VERBOSE: regsvr32.exe / s msxml6.dll +VERBOSE: regsvr32.exe / s actxprxy.dll +VERBOSE: regsvr32.exe / s softpub.dll +VERBOSE: regsvr32.exe / s wintrust.dll +VERBOSE: regsvr32.exe / s dssenh.dll +VERBOSE: regsvr32.exe / s rsaenh.dll +VERBOSE: regsvr32.exe / s gpkcsp.dll +VERBOSE: regsvr32.exe / s sccbase.dll +VERBOSE: regsvr32.exe / s slbcsp.dll +VERBOSE: regsvr32.exe / s cryptdlg.dll +VERBOSE: regsvr32.exe / s oleaut32.dll +VERBOSE: regsvr32.exe / s ole32.dll +VERBOSE: regsvr32.exe / s shell32.dll +VERBOSE: regsvr32.exe / s initpki.dll +VERBOSE: regsvr32.exe / s wuapi.dll +VERBOSE: regsvr32.exe / s wuaueng.dll +VERBOSE: regsvr32.exe / s wuaueng1.dll +VERBOSE: regsvr32.exe / s wucltui.dll +VERBOSE: regsvr32.exe / s wups.dll +VERBOSE: regsvr32.exe / s wups2.dll +VERBOSE: regsvr32.exe / s wuweb.dll +VERBOSE: regsvr32.exe / s qmgr.dll +VERBOSE: regsvr32.exe / s qmgrprxy.dll +VERBOSE: regsvr32.exe / s wucltux.dll +VERBOSE: regsvr32.exe / s muweb.dll +VERBOSE: regsvr32.exe / s wuwebv.dll +Step 7: Reset WinSock +VERBOSE: netsh winsock reset +Step 8: Reset Proxy +VERBOSE: netsh winhttp reset proxy +Step 9: Start Windows Update services +VERBOSE: Cryptographic Services (cryptsvc) +VERBOSE: Application Identity (appidsvc) +VERBOSE: Windows Update (wuauserv) +VERBOSE: Background Intelligent Transfer Service (BITS) +Step 10: Start Windows Update services +VERBOSE: wuauclt /resetauthorization /detectnow + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUHistory + Get + WUHistory + + Get list of updates history. + + + + Use function Get-WUHistory to get list of installed updates on specific machine. + + + + + Get-WUHistory + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Last + + Last X history entry. + + int + + System.Int32 + + + 0 + + + + MaxDate + + Filter results by date. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: Export-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: Export-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + MaxDate + + Filter results by date. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + Last + + Last X history entry. + + int + + System.Int32 + + + 0 + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.History + + + + OutputType for History objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get Windows Update history. + +Get-WUHistory + +ComputerName Operationname Date KB Title +------------ ------------- ---- -- ----- +MG-PC Installation 30.08.2017 12:03:53 KB2267602 Definition Update for Windows Defender - KB2267602(Defini... +MG-PC Installation 29.08.2017 11:49:50 KB3186568 Microsoft .NET Framework 4.7 for Windows 10 Version 1607 a... +MG-PC Installation 29.08.2017 11:30:37 KB4035631 2017-08 Update for Windows Server 2016 for x64-based Syste... +MG-PC Installation 29.08.2017 11:21:12 KB890830 Windows Malicious Software Removal Tool for Windows 8, 8.1... +MG-PC Installation 29.08.2017 07:53:36 KB2267602 Definition Update for Windows Defender - KB2267602 (Defini... +MG-PC Installation 27.08.2017 07:53:39 KB2267602 Definition Update for Windows Defender - KB2267602 (Defini... +MG-PC Installation 25.08.2017 07:54:38 KB2267602 Definition Update for Windows Defender - KB2267602 (Defini... +MG-PC Installation 23.08.2017 13:01:26 KB2267602 Definition Update for Windows Defender - KB2267602 (Defini... +MG-PC Installation 23.08.2017 12:45:45 KB4023307 Security Update for Microsoft Silverlight (KB4023307) +MG-PC Installation 23.08.2017 07:53:56 KB2267602 Definition Update for Windows Defender - KB2267602 (Defini... + + + ---------- EXAMPLE 2 ---------- + Get Windows Update Agent history for last 24h. + +Get-WUHistory -MaxDate (Get-Date).AddDays(-1) + +ComputerName Operationname Date KB Title +------------ ------------- ---- -- ----- +MG-PC Installation 30.08.2017 12:03:53 KB2267602 Definition Update for Windows Defender - KB2267602(Defini... + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUInstallerStatus + Get + WUInstallerStatus + + Get Windows Update Installer status. + + + + Use Get-WUInstallerStatus cmdlet to show Windows Update Installer status. + + + + + Get-WUInstallerStatus + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + + PSWindowsUpdate.InstallerStatus + + + + OutputType for InstallerStatus objects. + + + + + + ---------- EXAMPLE 1 ---------- + Check if Windows Update Installer is busy. + +Get-WUInstallerStatus + +ComputerName IsBusy +------------ ------ +MG-PC False + + + ---------- EXAMPLE 2 ---------- + Check if Windows Update Installer is busy in silent mode. Return only True (isBusy) or False (isFree). + +Get-WUInstallerStatus -Silent + +False + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUJob + Get + WUJob + + Get invoked WUJob. + + + + Use Get-WUJob cmdlet to get invoked WUJob in Task Scheduler. + + + + + Get-WUJob + + + ClearExpired + + Clear expired WUJob. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + + + + ClearExpired + + Clear expired WUJob. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.WUJob + + + + OutputType for WUJob. + + + + + + ---------- EXAMPLE 1 ---------- + Get invoked WUJob on remote machine. + +Get-WUJob -ComputerName MG-PC + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Invoke-WUJob + Invoke + WUJob + + Invoke WUJobs by Task Schduler. + + + + Use Invoke-WUJobs cmdlet to invoke PSWindowsUpdate actions remotly. It Based on TaskScheduler because CreateUpdateDownloader() and CreateUpdateInstaller() methods can't be called from a remote computer - E_ACCESSDENIED. + Note: Because we do not have the ability to interact, is recommended use -AcceptAll for Install-WindowsUpdate. + + + + + Invoke-WUJob + + + TriggerDate + + Specify Time trigger for Task Scheduler job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + EndBoundary + + Specify EndBoundary for Task Scheduler trigger. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + Force + + Force update old Task Scheduler Job if it's available. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hidden + + Specify if task must be hidden. Default is true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + True + + + + Script + + Specify PowerShell script that you what to run. Default is {ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log} + + string + + System.String + + + ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + PSWindowsUpdate + + + + + Invoke-WUJob + + + TriggerAtStart + + Specify system startup trigger for Task Scheduler job. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + EndBoundary + + Specify EndBoundary for Task Scheduler trigger. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + Force + + Force update old Task Scheduler Job if it's available. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hidden + + Specify if task must be hidden. Default is true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + True + + + + Script + + Specify PowerShell script that you what to run. Default is {ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log} + + string + + System.String + + + ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + PSWindowsUpdate + + + + + Invoke-WUJob + + + RunNow + + Run Task Scheduler job immediately. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + EndBoundary + + Specify EndBoundary for Task Scheduler trigger. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + Force + + Force update old Task Scheduler Job if it's available. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Hidden + + Specify if task must be hidden. Default is true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + True + + + + Script + + Specify PowerShell script that you what to run. Default is {ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log} + + string + + System.String + + + ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + PSWindowsUpdate + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + TaskName + + Specify custom name for Task Scheduler job. Default is 'PSWindowsUpdate'. + + string + + System.String + + + PSWindowsUpdate + + + + Hidden + + Specify if task must be hidden. Default is true. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + True + + + + EndBoundary + + Specify EndBoundary for Task Scheduler trigger. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + TriggerDate + + Specify Time trigger for Task Scheduler job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + TriggerAtStart + + Specify system startup trigger for Task Scheduler job. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RunNow + + Run Task Scheduler job immediately. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Script + + Specify PowerShell script that you what to run. Default is {ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log} + + string + + System.String + + + ipmo PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File $Env:TEMP\PSWindowsUpdate.log + + + + Force + + Force update old Task Scheduler Job if it's available. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + ---------- EXAMPLE 1 ---------- + Invoke Install-WindowsUpdate on remote machine today at 6:00 PM. + +Invoke-WUJob -ComputerName MG-PC -Script "ipmo PSWindowsUpdate; Install-WindowsUpdate -AcceptAll | Out-File C:\PSWindowsUpdate.log" -TriggerDate (Get-Date -Hour 18 -Minute 0 -Second 0) + +Confirm +Are you sure you want to perform this action? +Performing the operation "Invoke WU job: powershell.exe -Command "ipmo PSWindowsUpdate; Install-WindowsUpdate -AcceptAll | Out-File C:\PSWindowsUpdate.log"" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WULastResults + Get + WULastResults + + Get Windows Update results. + + + + Use Get-WULastResults cmdlet to get Windows Update LastSearchSuccessDate and LastInstallationSuccessDate. + + + + + Get-WULastResults + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.LastResults + + + + OutputType for LastResult objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get last Windows Update results. + +Get-WULastResults + +ComputerName LastSearchSuccessDate LastInstallationSuccessDate +------------ --------------------- --------------------------- +MG-PC 30.08.2017 14:02:11 03.07.2017 07:35:27 + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Update-WUModule + Update + WUModule + + Update PSWindowsUpdate module. + + + + Use Use Update-WUModule cmdlet to remote update PSWindowsUpdate module. + + + + + Update-WUModule + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Local + + Update from current module. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Update-WUModule + + + Online + + Update from PSGallery. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Online + + Update from PSGallery. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Local + + Update from current module. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + ---------- EXAMPLE 1 ---------- + Update PSWindowsUpdate module from PSGallery + +Update-WUModule -ComputerName MG-PC -Online + + + ---------- EXAMPLE 2 ---------- + Update PSWindowsUpdate module from current serwer. Require SMB connection to destination machine. + +Update-WUModule -ComputerName MG-PC -Local + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUOfflineMSU + Get + WUOfflineMSU + + Get offline MSU package. + + + + Use Get-WUOfflineMSU cmdlet to download MSU package from Microsoft Update Catalog website. + + + + + Get-WUOfflineMSU + + + Destination + + Destination for downloaded files. + + string + + System.String + + + + + + KBArticleID + + Finds updates that contain a KBArticleID. + + string + + System.String + + + + + + AcceptAll + + Do not ask confirmation for download updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + KBArticleID + + Finds updates that contain a KBArticleID. + + string + + System.String + + + + + + Destination + + Destination for downloaded files. + + string + + System.String + + + + + + AcceptAll + + Do not ask confirmation for download updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String + + + + Finds updates that contain a KBArticleID. + + + + + + + ---------- EXAMPLE 1 ---------- + Download package for KB4551762. +PS> Get-WUOfflineMSU -KBArticleID 4551762 -Destination C:\Temp + + Confirm + Are you sure you want to perform this action? + Performing the operation "(20.04.2020 14:27:17) 2020-03 Cumulative Update for Windows Server, version 1909 for + x64-based Systems (KB4551762)[354.4 MB]" on target "DESKTOP-GCQBCBS". + [Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): N + + Confirm + Are you sure you want to perform this action? + Performing the operation "(20.04.2020 14:27:19) 2020-03 Cumulative Update for Windows 10 Version 1909 for x64-based + Systems(KB4551762) [354.4 MB]" on target "DESKTOP-GCQBCBS". + [Y] Yes[A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y + + Confirm + Are you sure you want to perform this action? + Performing the operation "(20.04.2020 14:27:23) 2020-03 Cumulative Update for Windows 10 Version 1903 for x64-based + Systems(KB4551762) [354.4 MB]" on target "DESKTOP-GCQBCBS". + [Y] Yes[A]Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): L + + X Result Title LastUpdated Size + - ------ ----- ----------- ---- + 1 Rejected 2020-03 Cumulative Update for Windows Server, version 1909 for x64-based Systems (... 3/12/2020 354.4 MB + 1 Accepted 2020-03 Cumulative Update for Windows 10 Version 1909 for x64-based Systems (KB455... 3/12/2020 354.4 MB + 1 Rejected 2020-03 Cumulative Update for Windows 10 Version 1903 for x64-based Systems (KB455... 3/12/2020 354.4 MB + 1 Rejected 2020-03 Cumulative Update for Windows 10 Version 1909 for x86-based Systems (KB455... 3/12/2020 191.7 MB + 1 Rejected 2020-03 Cumulative Update for Windows 10 Version 1903 for x86-based Systems (KB455... 3/12/2020 191.7 MB + 1 Rejected 2020-03 Cumulative Update for Windows 10 Version 1909 for ARM64-based Systems (KB4... 3/12/2020 396.1 MB + 1 Rejected 2020-03 Cumulative Update for Windows Server, version 1903 for x64-based Systems (... 3/12/2020 354.4 MB + 1 Rejected 2020-03 Cumulative Update for Windows 10 Version 1903 for ARM64-based Systems (KB4... 3/12/2020 396.1 MB + 2 Downloaded 2020-03 Cumulative Update for Windows 10 Version 1909 for x64-based Systems (KB455... 3/12/2020 354.4 MB + +PS> Get-ChildItem C:\Temp + Directory: C:\Temp + + Mode LastWriteTime Length Name + ---- ------------- ------ ---- + -a---- 12.03.2020 07:03 371656774 windows10.0-kb4551762-x64_dacef156c781f2018d94d5a5286076610ba97279.msu + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WURebootStatus + Get + WURebootStatus + + Get Windows Update reboot status. + + + + Use Get-WURebootStatus cmdlet to check if reboot is needed. + + + + + Get-WURebootStatus + + + AutoReboot + + Do not ask for reboot if it needed, but do it now. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WURebootStatus + + + ScheduleReboot + + Specify schedule time for reboot. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WURebootStatus + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Get-WURebootStatus + + + CancelReboot + + Cancel scheduled reboot. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Silent + + Return true/false only. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoReboot + + Do not ask for reboot if it needed, but do it now. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleReboot + + Specify schedule time for reboot. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + CancelReboot + + Cancel scheduled reboot. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.Management.Automation.SwitchParameter + + + + Return true/false only. + + + + + + + + PSWindowsUpdate.RebootStatus + + + + OutputType for RebootStatus objects. + + + + + + ---------- EXAMPLE 1 ---------- + Check if restart is necessary. If yes, ask to do this or don't. + +Get-WURebootStatus + +Reboot is required. Do it now ? [Y/N] (default is 'N') +ComputerName RebootRequired RebootScheduled +------------ -------------- --------------- +MG-PC True + + + ---------- EXAMPLE 2 ---------- + Check if restart is necessary. If yes, then shedule it. + +Get-WURebootStatus -ScheduleReboot (Get-Date -Hour 18 -Minute 0 -Second 0) + +ComputerName RebootRequired RebootScheduled +------------ -------------- --------------- +MG-PC True 31.08.2017 18:00:00 + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Enable-WURemoting + Enable + WURemoting + + Enable firewall rules for PSWindowsUpdate remoting. + + + + Use Enable-WURemoting cmdlet to enable nessesery firewall rules for PSWindowsUpdate remoting. + + + + + Enable-WURemoting + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + LocalAccountTokenFilterPolicy + + Set LocalAccountTokenFilterPolicy registry entry to builds an elevated token on the target remote computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WinRMPublic + + Enable WinRM Public access from all subnets. Default access is only enabled from local subnet. Required for workgroup computers. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + LocalAccountTokenFilterPolicy + + Set LocalAccountTokenFilterPolicy registry entry to builds an elevated token on the target remote computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WinRMPublic + + Enable WinRM Public access from all subnets. Default access is only enabled from local subnet. Required for workgroup computers. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ---------- EXAMPLE 1 ---------- + Enable firewall rules for PSWindowsUpdate remoting. + +Enable-WURemoting -Verbose + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Add-WUServiceManager + Add + WUServiceManager + + Register a new Windows Update API Service Manager. + + + + Use Add-WUServiceManager cmdlet to register new Windows Update Service Manager. + It's combination old 'Add-WUServiceManager' and 'Add-WUOfflineSync' functions to register online and offline ServiceManager + + + + + Add-WUServiceManager + + + ServiceID + + An identifier for the service to be registered. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Don't return output. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Add-WUServiceManager + + + MicrosoftUpdate + + Register Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Don't return output. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Add-WUServiceManager + + + ServiceID + + An identifier for the service to be registered. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + AddServiceFlag + + A combination of AddServiceFlag values: \r\n0x1 - asfAllowPendingRegistration \r\n0x2 - asfAllowOnlineRegistration \r\n0x4 - asfRegisterServiceWithAU + + int + + System.Int32 + + + 2 + + + + AuthorizationCabPath + + The path of the Microsoft signed local cabinet file (.cab) that has the information that is required for a service registration. If empty, the update agent searches for the authorization cabinet file (.cab) during service registration when a network connection is available. + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Silent + + Don't return output. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + Add-WUServiceManager + + + ScanFileLocation + + Path to Windows Update offline scan file (wsusscan.cab or wsusscn2.cab). + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ServiceName + + Name under which it will be registered Windows Update offline service. Default name is 'Offline Sync Service'. + + string + + System.String + + + Offline Sync Service + + + + Silent + + Don't return output. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + ServiceID + + An identifier for the service to be registered. + Examples Of ServiceID: \r\n \r\n -- Windows Update 9482f4b4-e343-43b6-b170-9a65bc822c77 \r\n -- Microsoft Update 7971f918-a847-4430-9279-4a52d1efe18d \r\n -- Windows Store 117cab2d-82b1-4b5a-a08c-4d62dbee7782 \r\n -- Windows Server Update Service 3da21691-e39d-4da6-8a4b-b43877bcb1b7 + + string + + System.String + + + + + + AddServiceFlag + + A combination of AddServiceFlag values: \r\n0x1 - asfAllowPendingRegistration \r\n0x2 - asfAllowOnlineRegistration \r\n0x4 - asfRegisterServiceWithAU + + int + + System.Int32 + + + 2 + + + + AuthorizationCabPath + + The path of the Microsoft signed local cabinet file (.cab) that has the information that is required for a service registration. If empty, the update agent searches for the authorization cabinet file (.cab) during service registration when a network connection is available. + + string + + System.String + + + + + + MicrosoftUpdate + + Register Microsoft Update Service Manager - '7971f918-a847-4430-9279-4a52d1efe18d' + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ServiceName + + Name under which it will be registered Windows Update offline service. Default name is 'Offline Sync Service'. + + string + + System.String + + + Offline Sync Service + + + + ScanFileLocation + + Path to Windows Update offline scan file (wsusscan.cab or wsusscn2.cab). + + string + + System.String + + + + + + Silent + + Don't return output. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.ServiceManager + + + + OutputType for ServiceManager objects. + + + + + + ---------- EXAMPLE 1 ---------- + Try register Microsoft Update Service by custom ServiceID. + +Add-WUServiceManager -ServiceID "7971f918-a847-4430-9279-4a52d1efe18d" + +Confirm +Are you sure you want to perform this action? +Performing the operation "Register Windows Update Service Manager: 7971f918-a847-4430-9279-4a52d1efe18d" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ServiceID IsManaged IsDefault Name +--------- --------- --------- ---- +7971f918-a847-4430-9279-4a52d1efe18d False False Microsoft Update + + + ---------- EXAMPLE 2 ---------- + Try register Microsoft Update service as Service Manager. + +Add-WUServiceManager -MicrosoftUpdate + +Confirm +Are you sure you want to perform this action? +Performing the operation "Register Windows Update Service Manager: 7971f918-a847-4430-9279-4a52d1efe18d" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ServiceID IsManaged IsDefault Name +--------- --------- --------- ---- +7971f918-a847-4430-9279-4a52d1efe18d False False Microsoft Update + + + ---------- EXAMPLE 3 ---------- + Try register Offline Sync Service from file C:\wsusscn2.cab. + +Add-WUServiceManager -ScanFileLocation C:\wsusscn2.cab + +Confirm +Are you sure you want to perform this action? +Performing the operation "Register Offline Windows Update Service Manager: C:\wsusscn2.cab" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ServiceID IsManaged IsDefault Name +--------- --------- --------- ---- +7e1364ef-e30e-4f4e-9c66-84194eebcbbe False False Offline Sync Service + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUServiceManager + Get + WUServiceManager + + Get Service Manager configuration. + + + + Use Get-WUServiceManager cmdlet to get available configuration of update services. + + + + + Get-WUServiceManager + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ServiceID + + Get specific Service Manager if it's available. + + string + + System.String + + + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + ServiceID + + Get specific Service Manager if it's available. + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.ServiceManager + + + + OutputType for ServiceManager objects. + + + + + + ---------- EXAMPLE 1 ---------- + Check currently available Windows Update Services on machine. + +Get-WUServiceManager + +ServiceID IsManaged IsDefault Name +--------- --------- --------- ---- +9482f4b4-e343-43b6-b170-9a65bc822c77 False False Windows Update +7971f918-a847-4430-9279-4a52d1efe18d False False Microsoft Update +3da21691-e39d-4da6-8a4b-b43877bcb1b7 True True Windows Server Update Service +13df3d8f-78d7-4eb8-bb9c-2a101870d350 False False Offline Sync Service2 +a8f3b5e6-fb1f-4814-a047-2257d39c2460 False False Offline Sync Service + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Remove-WUServiceManager + Remove + WUServiceManager + + Remove windows update service manager. + + + + Use Remove-WUServiceManager cmdlet to unregister Windows Update Service Manager. + + + + + Remove-WUServiceManager + + + ServiceID + + Specify ServiceID of Service Manager that you want to remove. + + string + + System.String + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ScheduleJob + + Specify schedule time job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + ScheduleJob + + Specify schedule time job. + + DateTime + + System.DateTime + + + 01.01.0001 00:00:00 + + + + ServiceID + + Specify ServiceID of Service Manager that you want to remove. + + string + + System.String + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + ---------- EXAMPLE 1 ---------- + Try unregister Microsoft Update Service. + +Remove-WUServiceManager -ServiceID "7971f918-a847-4430-9279-4a52d1efe18d" + +Confirm +Are you sure you want to perform this action? +Performing the operation "Unregister Windows Update Service Manager: 7971f918-a847-4430-9279-4a52d1efe18d" on target "MG-PC". + +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUSettings + Get + WUSettings + + Get Windows Update Client settings. + + + + Use Get-WUSettings cmdlet to get current configuration of Windows Update Client. + + + + + Get-WUSettings + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.WUSettings + + + + OutputType for WUSettings objects. + + + + + + ---------- EXAMPLE 1 ---------- + Get current Windows Update Client configuration. + +Get-WUSettings + +ComputerName : MG-PC +AcceptTrustedPublisherCerts : 0 +WUServer : https://wsus.commandlinegeeks.com +WUStatusServer : https://wsus.commandlinegeeks.com +DetectionFrequencyEnabled : 1 +DetectionFrequency : 2 +NoAutoRebootWithLoggedOnUsers : 1 +RebootRelaunchTimeoutEnabled : 1 +RebootRelaunchTimeout : 240 +IncludeRecommendedUpdates : 0 +NoAutoUpdate : 0 +AUOptions : 2 - Notify before download +ScheduledInstallDay : 0 - Every Day +ScheduledInstallTime : 4 +UseWUServer : 1 + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Set-WUSettings + Set + WUSettings + + Set Windows Update Client settings. + + + + Use Set-WUSettings cmdlet to Set configuration of Windows Update Client. + + + + + Set-WUSettings + + + AcceptTrustedPublisherCerts + + Enabled - The WSUS server distributes available signed non-Microsoft updates. + Disabled - The WSUS server does not distribute available signed non-Microsoft updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + AutoInstallMinorUpdates + + Silently install minor updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DetectionFrequency + + Time between detection cycles. Time in hours (1–22). + + int + + System.Int32 + + + 0 + + + + DetectionFrequencyEnabled + + Enable/Disable detection frequency. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DisableWindowsUpdateAccess + + Disables/Enables access to Windows Update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IncludeRecommendedUpdates + + Enable/Disable recommended updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NoAutoRebootWithLoggedOnUsers + + Logged-on user can decide whether to restart the client computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NoAutoUpdate + + Enable/Disable Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NonAdministratorsElevated + + Enabled - All members of the Users security group can approve or disapprove updates. + Disabled - Only members of the Administrators security group can approve or disapprove updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NotificationLevel + + Notify mode: "Not configured", "Disabled", "Notify before download", "Notify before installation", "Scheduled installation", "Users configure" + + string + + System.String + + + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + RebootRelaunchTimeout + + Time between prompts for a scheduled restart. Time in minutes (1–1440). + + int + + System.Int32 + + + 0 + + + + RebootRelaunchTimeoutEnabled + + Enable/Disable RebootRelaunchTimeout. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RebootWarningTimeout + + Length, in minutes, of the restart warning countdown after updates have been installed that have a deadline or scheduled updates. Time in minutes (1–30). + + int + + System.Int32 + + + 0 + + + + RebootWarningTimeoutEnabled + + Enable/Disable RebootWarningTimeout. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RescheduleWaitTime + + Time in minutes that Automatic Updates waits at startup before it applies updates from a missed scheduled installation time. Time in minutes (1–60). + + int + + System.Int32 + + + 0 + + + + ScheduledInstallDay + + Scheduled day of install: "Every day", "Every Sunday", "Every Monday", "Every Tuesday", "Every Wednesday", "Every Thursday", ""Every Friday", "EverySaturday". Only valid if NotificationLevel (AUOptions) = "Scheduled installation" + Starting with Windows 8 and Windows Server 2012, ScheduledInstallationDay are not supported and will return unreliable values.If you try to modify these properties, the operation will appear to succeed but will have no effect. + + string + + System.String + + + + + + ScheduledInstallTime + + Scheduled time of install in 24-hour format(0–23). + Starting with Windows 8 and Windows Server 2012, ScheduledInstallTime are not supported and will return unreliable values.If you try to modify these properties, the operation will appear to succeed but will have no effect. + + int + + System.Int32 + + + 0 + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + TargetGroup + + Name of the computer group to which the computer belongs. + + string + + System.String + + + + + + TargetGroupEnabled + + Use/Do not use client-side targeting. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + UseWUServer + + The computer gets its updates from a WSUS server or from Microsoft Update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WUServer + + HTTP(S) URL of the WSUS server that is used by Automatic Updates and API callers (by default). + + string + + System.String + + + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + AcceptTrustedPublisherCerts + + Enabled - The WSUS server distributes available signed non-Microsoft updates. + Disabled - The WSUS server does not distribute available signed non-Microsoft updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DisableWindowsUpdateAccess + + Disables/Enables access to Windows Update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NonAdministratorsElevated + + Enabled - All members of the Users security group can approve or disapprove updates. + Disabled - Only members of the Administrators security group can approve or disapprove updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + TargetGroup + + Name of the computer group to which the computer belongs. + + string + + System.String + + + + + + TargetGroupEnabled + + Use/Do not use client-side targeting. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + WUServer + + HTTP(S) URL of the WSUS server that is used by Automatic Updates and API callers (by default). + + string + + System.String + + + + + + NotificationLevel + + Notify mode: "Not configured", "Disabled", "Notify before download", "Notify before installation", "Scheduled installation", "Users configure" + + string + + System.String + + + + + AUOptions + + Notify mode: "Not configured", "Disabled", "Notify before download", "Notify before installation", "Scheduled installation", "Users configure" + This is an alias of the NotificationLevel parameter. + + string + + System.String + + + + + + AutoInstallMinorUpdates + + Silently install minor updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + DetectionFrequency + + Time between detection cycles. Time in hours (1–22). + + int + + System.Int32 + + + 0 + + + + DetectionFrequencyEnabled + + Enable/Disable detection frequency. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + IncludeRecommendedUpdates + + Enable/Disable recommended updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NoAutoRebootWithLoggedOnUsers + + Logged-on user can decide whether to restart the client computer. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + NoAutoUpdate + + Enable/Disable Automatic Updates. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RebootRelaunchTimeout + + Time between prompts for a scheduled restart. Time in minutes (1–1440). + + int + + System.Int32 + + + 0 + + + + RebootRelaunchTimeoutEnabled + + Enable/Disable RebootRelaunchTimeout. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RebootWarningTimeout + + Length, in minutes, of the restart warning countdown after updates have been installed that have a deadline or scheduled updates. Time in minutes (1–30). + + int + + System.Int32 + + + 0 + + + + RebootWarningTimeoutEnabled + + Enable/Disable RebootWarningTimeout. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + RescheduleWaitTime + + Time in minutes that Automatic Updates waits at startup before it applies updates from a missed scheduled installation time. Time in minutes (1–60). + + int + + System.Int32 + + + 0 + + + + ScheduledInstallDay + + Scheduled day of install: "Every day", "Every Sunday", "Every Monday", "Every Tuesday", "Every Wednesday", "Every Thursday", ""Every Friday", "EverySaturday". Only valid if NotificationLevel (AUOptions) = "Scheduled installation" + Starting with Windows 8 and Windows Server 2012, ScheduledInstallationDay are not supported and will return unreliable values.If you try to modify these properties, the operation will appear to succeed but will have no effect. + + string + + System.String + + + + + + ScheduledInstallTime + + Scheduled time of install in 24-hour format(0–23). + Starting with Windows 8 and Windows Server 2012, ScheduledInstallTime are not supported and will return unreliable values.If you try to modify these properties, the operation will appear to succeed but will have no effect. + + int + + System.Int32 + + + 0 + + + + UseWUServer + + The computer gets its updates from a WSUS server or from Microsoft Update. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + + PSWindowsUpdate.WUSettings + + + + OutputType for WUSettings objects. + + + + + + ---------- EXAMPLE 1 ---------- + Enable IncludeRecommendedUpdates attributes. + +Set-WUSettings -IncludeRecommendedUpdates + +Confirm +Are you sure you want to perform this action? +Performing the operation "Set Windows Update settings" on target "MG-PC". +[Y] Yes[A] Yes to All [N] No[L] No to All [S] Suspend[?] Help (default is "Y"): Y + +ComputerName IncludeRecommendedUpdates +------------ ------------------------- +MG-PC True + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + + + + Get-WUTest + Get + WUTest + + Test cmdlet. + + + + Use Get-WUTest cmdlet to test. + + + + + Get-WUTest + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + TestParam + + Test parameter. + + string + + System.String + + + + + + + + + ComputerName + + Specify one or more computer names for remote connection. + + string[] + + System.String[] + + + + + + Credential + + Specify alternative credential. + + PSCredential + + System.Management.Automation.PSCredential + + + + + + SendReport + + Send report email to specific recipients. + Requires the parameter -PSWUSettings or declare the PSWUSettings.xml file in ModuleBase path. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + PSWUSettings + + Required parameter for -SendReport. + Passes the parameters (as hashtable) necessary to send the report: \r\n@{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25];[Subject="Alternative Subject"];[Properties="Alternative object properties"];[Style="Table|List"]} + Send parameters can also be saved to a PSWUSettings.xml file in ModuleBase path: \r\nExport-Clixml @{SmtpServer="your.smtp.server";From="sender@email.address";To="recipient@email.address";[Port=25]}" + + Hashtable + + System.Collections.Hashtable + + + + + + Debuger + + Debuger return original exceptions. + + SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + TestParam + + Test parameter. + + string + + System.String + + + + + + + + System.String[] + + + + Specify one or more computer names for remote connection. + + + + + + + ---------- EXAMPLE 1 ---------- + Test. + +Get-WUTest + + + + + Author Blog + https://commandlinegeeks.wordpress.com/ + + + + \ No newline at end of file diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psd1 b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psd1 new file mode 100644 index 0000000..a71f340 Binary files /dev/null and b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psd1 differ diff --git a/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psm1 b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psm1 new file mode 100644 index 0000000..53b05ed Binary files /dev/null and b/uninstall-kb-pswindowsupdate/PSWindowsUpdate/2.2.0.3/PSWindowsUpdate.psm1 differ diff --git a/uninstall-kb-pswindowsupdate/readme.md b/uninstall-kb-pswindowsupdate/readme.md new file mode 100644 index 0000000..2462a4a --- /dev/null +++ b/uninstall-kb-pswindowsupdate/readme.md @@ -0,0 +1,34 @@ +# Uninstall a Windows Update by KB (PSWindowsUpdate) + +Minimal helper and examples to remove an installed Windows update by its **KB** number using the **PSWindowsUpdate** module. + +## Requirements +- Run PowerShell **as Administrator**. +- Module: `PSWindowsUpdate` (install if needed: `Install-Module PSWindowsUpdate -Scope CurrentUser`). +- A reboot may be required after removal. + +## Quick commands (no wrapper) +```powershell +# List installed updates matching the KB +Get-WindowsUpdate -IsInstalled -KBArticleID KB5028952 + +# Uninstall (no auto-restart) +Remove-WindowsUpdate -KBArticleID KB5028952 -NoRestart -Confirm:$false +``` + +## Script usage +If you saved the wrapper as `Remove-KB.ps1`: +```powershell +# Example +.\Remove-KB.ps1 -KB KB5028952 -NoRestart +``` + +## Notes +- Some updates (especially **Servicing Stack Updates**) cannot be uninstalled. +- If removal via PSWindowsUpdate fails for a cumulative update, find the exact package name and try DISM: + ```powershell + DISM /Online /Get-Packages + DISM /Online /Remove-Package /PackageName: /Quiet /NoRestart + ``` +- Logs: `C:\Windows\Logs\WindowsUpdate\windowsupdate.log` and `C:\Windows\Logs\CBS\CBS.log`. + diff --git a/uninstall-kb-pswindowsupdate/uninstallKB.ps1 b/uninstall-kb-pswindowsupdate/uninstallKB.ps1 new file mode 100644 index 0000000..7d9b5e3 --- /dev/null +++ b/uninstall-kb-pswindowsupdate/uninstallKB.ps1 @@ -0,0 +1,36 @@ +#Requires -RunAsAdministrator +#Requires -Modules PSWindowsUpdate + +param( + [Parameter(Mandatory)] + [ValidatePattern('^(?i:KB)?\d+$')] + [string]$KB, + [switch]$NoRestart +) + +# Normalize input to "KBxxxxxxx" +if ($KB -match '^\d+$') { $KB = "KB$KB" } + +try { + Import-Module PSWindowsUpdate -ErrorAction Stop + + # Query only installed updates matching the KB + $installed = Get-WindowsUpdate -IsInstalled -KBArticleID $KB -ErrorAction SilentlyContinue + + if (-not $installed) { + Write-Host "Update $KB not found on this system." + return + } + + Write-Host "Found installed update: $KB" + $removeParams = @{ KBArticleID = $KB; Confirm = $false } + if ($NoRestart) { $removeParams['NoRestart'] = $true } + + Write-Host "Uninstalling $KB ..." + Remove-WindowsUpdate @removeParams -ErrorAction Stop + Write-Host "Uninstall command issued for $KB." + if (-not $NoRestart) { Write-Host "A restart may be required." } +} +catch { + Write-Error "Failed to uninstall $KB. $($_.Exception.Message)" +} diff --git a/uninstall-kb-remove-windows-package/readme.md b/uninstall-kb-remove-windows-package/readme.md new file mode 100644 index 0000000..b2b3f5e --- /dev/null +++ b/uninstall-kb-remove-windows-package/readme.md @@ -0,0 +1,19 @@ +# Remove Windows Updates by KB (PowerShell) + +Uninstalls all installed Windows packages whose name matches a given **KB** via DISM PowerShell cmdlets. + +## Usage +```powershell +# List installed packages and filter by KB +Get-WindowsPackage -Online | Where-Object { $_.PackageName -match "KB5032189" } | Select-Object PackageName, State, InstallTime +``` + +```powershell +# Uninstall all packages matching the KB +Remove-Package -KB "KB4589210" +``` + +## Notes & limitations +MSU files: Remove-WindowsPackage removes packages in the image (.cab/package identities), not .msu directly +SSUs can’t be uninstalled: Servicing Stack Updates modify the update stack and are not removable. +After ResetBase: If you ran DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase, existing update packages can no longer be uninstalled. \ No newline at end of file diff --git a/uninstall-kb-remove-windows-package/remove.ps1 b/uninstall-kb-remove-windows-package/remove.ps1 new file mode 100644 index 0000000..1844592 --- /dev/null +++ b/uninstall-kb-remove-windows-package/remove.ps1 @@ -0,0 +1,33 @@ +function Remove-Package { + param( + [string]$KB + ) + + # Find matching package(s) + $packages = Get-WindowsPackage -Online | Where-Object { $_.PackageName -match $KB } + + if($packages.Count -eq 0) { + Write-Host "No packages found matching $KB." + return + } + + # Display found packages + Write-Host "Packages found matching $KB" + $packages | ForEach-Object { Write-Host $_.PackageName } + + # Uninstall packages + foreach($package in $packages) { + try { + Write-Host "Uninstalling $($package.PackageName)..." + Remove-WindowsPackage -Online -PackageName $package.PackageName -NoRestart -ErrorAction Stop + Write-Host "$($package.PackageName) uninstalled successfully." + } catch { + Write-Error "Failed to uninstall $($package.PackageName). Error: $_" + } + } + + Write-Host "Please restart your computer." +} + +# Example usage +Remove-Package -KB "KB4589210" \ No newline at end of file