Skip to content
This repository was archived by the owner on Feb 28, 2021. It is now read-only.

Commit c5924e8

Browse files
committed
Update scripts
1 parent 7816640 commit c5924e8

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

scripts/Import-LatestUpdate.ps1

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#Requires -PSEdition Desktop
2+
<#
3+
.SYNOPSIS
4+
Imports the latest Windows packages into an MDT deployment share.
5+
6+
.DESCRIPTION
7+
This script will download Windows 10 updates and import the packages into an MDT deployment share.
8+
9+
.NOTES
10+
Author: Aaron Parker
11+
Twitter: @stealthpuppy
12+
13+
.LINK
14+
https://docs.stealthpuppy.com/docs/latestupdate
15+
16+
.PARAMETER UpdatePath
17+
The folder containing the updates to import into the MDT deployment share.
18+
19+
.PARAMETER DeployRoot
20+
Specify the path to the MDT deployment share.
21+
22+
.PARAMETER PackagePath
23+
A packges folder to import into relative to the Packages folder in the MDT share.
24+
25+
.PARAMETER Clean
26+
Before importing the latest updates into the target path, remove any existing update package.
27+
28+
.EXAMPLE
29+
Import-LatestUpdate -UpdatePath "C:\Temp\Updates" -DeployRoot "\\server\reference" -PackagePath "Windows 10"
30+
31+
Description:
32+
Download and import the latest updates into the deployment share \\server\reference under 'Packages\Windows 10'.
33+
#>
34+
[CmdletBinding(SupportsShouldProcess = $False)]
35+
Param (
36+
[Parameter(Mandatory = $False, HelpMessage = "Specify the folder containing the MSU update/s to import.")]
37+
[ValidateScript( { If (Test-Path $_ -PathType 'Container') { $True } Else { Throw "Cannot find path $_" } })]
38+
[ValidateNotNullOrEmpty()]
39+
[System.String] $UpdatePath = $PWD,
40+
41+
[Parameter(Mandatory = $True, HelpMessage = "Specify an MDT deployment share to apply the update to.")]
42+
[ValidateScript( { If (Test-Path $_ -PathType 'Container') { $True } Else { Throw "Cannot find path $_" } })]
43+
[ValidateNotNullOrEmpty()]
44+
[System.String] $DeployRoot,
45+
46+
[Parameter(Mandatory = $False, HelpMessage = "A sub-folder in the MDT Packages folder.")]
47+
[ValidateNotNullOrEmpty()]
48+
[System.String] $PackagePath,
49+
50+
[Parameter(Mandatory = $False, HelpMessage = "Remove the updates from the target MDT deployment share before importing the new updates.")]
51+
[System.Management.Automation.SwitchParameter] $Clean,
52+
53+
[Parameter(Mandatory = $False)]
54+
[System.String] $Drive = "DS004"
55+
)
56+
57+
# Import MDT module and mount deployment share
58+
$InstallDir = Resolve-Path -Path $((Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Deployment 4" -ErrorAction SilentlyContinue).Install_Dir)
59+
$MdtPath = Join-Path -Path $InstallDir -ChildPath "bin"
60+
$MdtModule = Resolve-Path -Path (Join-Path -Path $MdtPath -ChildPath "MicrosoftDeploymentToolkit.psd1")
61+
Try {
62+
Import-Module -Name $MdtModule -ErrorAction SilentlyContinue
63+
}
64+
Catch {
65+
Throw "Could not load MDT PowerShell Module. Please make sure that the MDT Workbench is installed correctly."
66+
Exit
67+
}
68+
$Drive = New-PSDrive -Name $Drive -PSProvider MDTProvider -Root $DeployRoot
69+
70+
# If $PackagePath is specified, use a sub-folder of MDT Share\Packages
71+
If ($PSBoundParameters.ContainsKey('PackagePath')) {
72+
$Dest = "$($Drive):\Packages\$($PackagePath)"
73+
Try {
74+
New-MdtPackagesFolder -Drive $Drive -Path $PackagePath -ErrorAction SilentlyContinue
75+
}
76+
Catch {
77+
Write-Warning -Message "Failed to create packages folder [$($Drive):\Packages\$($PackagePath)]"
78+
}
79+
}
80+
Else {
81+
# If no path specified, we'll import directly into the Packages folder
82+
$Dest = "$($Drive):\Packages"
83+
}
84+
Write-Host "Destination is: [$($Dest)]"
85+
86+
# If -Clean is specified, remove packages from the destination folder
87+
If ($Clean) {
88+
Write-Host "Cleaning: [$Dest]" -ForegroundColor Cyan
89+
Remove-MdtPackage -Path $Dest -Verbose
90+
}
91+
92+
# Ensure $UpdatePath exists
93+
If (Test-Path -Path $UpdatePath) {
94+
Write-Host "Path exists: [$UpdatePath]" -ForegroundColor Cyan
95+
}
96+
Else {
97+
New-Item -Path $UpdatePath -ItemType Directory
98+
}
99+
100+
# Download the updates
101+
Write-Host "Downloading cumulative updates." -ForegroundColor Cyan
102+
Get-LatestCumulativeUpdate | Where-Object { $_.Architecture -eq "x64" } | Save-LatestUpdate -Path $UpdatePath -Method WebClient
103+
104+
Write-Host "Downloading servicing stack updates." -ForegroundColor Cyan
105+
Get-LatestServicingStackUpdate | Where-Object { $_.Architecture -eq "x64" } | Save-LatestUpdate -Path $UpdatePath -Method WebClient
106+
107+
Write-Host "Downloading servicing stack updates." -ForegroundColor Cyan
108+
Get-LatestAdobeFlashUpdate | Where-Object { $_.Architecture -eq "x64" } | Save-LatestUpdate -Path $UpdatePath -Method WebClient
109+
110+
# Write-Host "Downloading Windows Defender updates." -ForegroundColor Cyan
111+
# Get-LatestWindowsDefenderUpdate | Save-LatestUpdate -Path $UpdatePath -Method WebClient
112+
113+
Write-Host "Downloading .NET Framework updates." -ForegroundColor Cyan
114+
Get-LatestNetFrameworkUpdate | Where-Object { $_.Version -eq "1903" } | Save-LatestUpdate -Path $UpdatePath -Method WebClient
115+
116+
117+
# Validate the provided local path and import the update package
118+
If ($UpdatePath -ne $False) {
119+
Try {
120+
Import-MdtPackage -Path $Dest -SourcePath $UpdatePath -ErrorAction SilentlyContinue -Verbose
121+
}
122+
Catch {
123+
Write-Warning -Message "Failed to import the package."
124+
}
125+
}
126+
Else {
127+
Write-Warning -Message "Validation failed on the provided path: [$UpdatePath]" -ErrorAction Stop
128+
}

tests/Invoke-LocalTest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
Param ()
77

88
# Invoke Pester tests and upload results to AppVeyor
9-
$res = Invoke-Pester -Path (Join-Path -Path $PWD -ChildPath "PublicFunctions.Tests.ps1") -OutputFormat NUnitXml -PassThru -ExcludeTag "AppVeyor"
9+
$res = Invoke-Pester -Path (Join-Path -Path $PWD -ChildPath "PublicFunctions.Tests.ps1") -PassThru -ExcludeTag "AppVeyor"
1010
If ($res.FailedCount -gt 0) { Throw "$($res.FailedCount) tests failed." }
1111
Write-Host ""

0 commit comments

Comments
 (0)