PoshCode Archive  Check-in [1f6dfc4c8c]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The script will launch Windows Update on your machine, and display the patches as they are being installed. Once installed, a result code will be displayed as well. If a reboot is needed, the script will take care of that automatically as well… change this
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1f6dfc4c8c84d5d53a21505f2b2ba892adde496b574c62418a794fbd8ca3b657
User & Date: JayneticMuffin 2018-06-10 13:58:55
Context
2018-06-10
13:58
Generate random passwords with specific complexity requirements check-in: e1534529d0 user: Jon Webster tags: trunk
13:58
The script will launch Windows Update on your machine, and display the patches as they are being installed. Once installed, a result code will be displayed as well. If a reboot is needed, the script will take care of that automatically as well… change this check-in: 1f6dfc4c8c user: JayneticMuffin tags: trunk
13:58
Wanted to create an unzip function for single files with an option to delete the originating zip, and also have a function for scanning through a folder structure recursively and providing the same functionality… and here it is. check-in: b60933d48d user: JayneticMuffin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added Automatic-Windows-Update.ps1.





























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# encoding: ascii
# api: powershell
# title: Automatic Windows Update
# description: The script will launch Windows Update on your machine, and display the patches as they are being installed.  Once installed, a result code will be displayed as well. If a reboot is needed, the script will take care of that automatically as well… change this
# version: 0.1
# author: JayneticMuffin
# license: CC0
# x-poshcode-id: 5669
# x-archived: 2015-01-09T20:22:09
# x-published: 2015-01-07T14:45:00
#
#
#Checking for available updates
Write-Host "  Checking for available updates... Please wait!" -ForegroundColor 'Yellow'
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$SearchResult = $UpdateSession.CreateUpdateSearcher().Search($criteria).Updates | ? {$_.Title -notmatch $skipUpdates}
$SearchResult = $SearchResult | Sort-Object LastDeploymentChangeTime -Descending
$totalUpdates = $SearchResult.Count

ForEach ($Update in $SearchResult) {
	If ($totalUpdates -eq $null) { $totalUpdates = 1}
	# Add Update to Collection 
	$UpdatesCollection = New-Object -ComObject Microsoft.Update.UpdateColl
	if ($Update.EulaAccepted -eq 0) { $Update.AcceptEula() }
	$null = $UpdatesCollection.Add($Update)
	
	# Download
	$fileSize = "{0:N0} MB" -f ($($Update.MaxDownloadSize) / 1MB)
	Write-Host "  Downloading ($($counter.ToString("00"))/$($totalUpdates.ToString("00"))) - $fileSize - " -ForegroundColor 'Yellow' -NoNewline
	$counter++
	Write-Host "$($Update.Title)" -ForegroundColor 'White'
	$UpdatesDownloader = $UpdateSession.CreateUpdateDownloader()
	$UpdatesDownloader.Updates = $UpdatesCollection
	$UpdatesDownloader.Priority = 3

	Write-Host "`t- Download " -NoNewline -ForegroundColor 'White'
	$DownloadResult = $UpdatesDownloader.Download()
	Switch ($DownloadResult.ResultCode) {
		0   { Write-Host "Not Started" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		1   { Write-Host "In Progress" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		2   { Write-Host "Succeeded" -ForegroundColor 'Green' }
		3   { Write-Host "Succeeded (with Errors)" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		4   { Write-Host "Failed" -ForegroundColor 'White' -BackgroundColor 'Red' }
		5   { Write-Host "Aborted" -ForegroundColor 'White' -BackgroundColor 'Red' }
	}

	# Install
	$UpdatesInstaller = $UpdateSession.CreateUpdateInstaller()
	$UpdatesInstaller.Updates = $UpdatesCollection

	Write-Host "`t- Install  " -NoNewline -ForegroundColor 'White'
	$InstallResult = $UpdatesInstaller.Install()
	Switch ($installResult.ResultCode) {
		0   { Write-Host "Not Started" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		1   { Write-Host "In Progress" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		2   { Write-Host "Succeeded" -ForegroundColor 'Green' }
		3   { Write-Host "Succeeded (with Errors)" -ForegroundColor 'Black' -BackgroundColor 'Yellow' }
		4   { Write-Host "Failed" -ForegroundColor 'White' -BackgroundColor 'Red' }
		5   { Write-Host "Aborted" -ForegroundColor 'White' -BackgroundColor 'Red' }
	}
	# Change the line below if you don't want to automatically reboot...
	If ($installResult.rebootRequired -eq 'True') { $needsReboot = $true }
}