Skip to content

Commit

Permalink
added PatchParentDisks script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaromir Kaspar committed Feb 24, 2021
1 parent f937244 commit 0604f02
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Scripts/1_Prereq.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function Get-WindowsBuildNumber {
}
}

# add createparentdisks and DownloadLatestCU scripts to Parent Disks folder
$FileNames="CreateParentDisk","DownloadLatestCUs"
# add createparentdisks, DownloadLatestCU and PatchParentDisks scripts to Parent Disks folder
$FileNames="CreateParentDisk","DownloadLatestCUs","PatchParentDisks"
foreach ($filename in $filenames){
$Path="$PSScriptRoot\ParentDisks\$FileName.ps1"
If (Test-Path -Path $Path){
Expand Down
92 changes: 92 additions & 0 deletions Tools/PatchParentDisks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Verify Running as Admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
If (-not $isAdmin) {
Write-Host "-- Restarting as Administrator" -ForegroundColor Cyan ; Start-Sleep -Seconds 1

if($PSVersionTable.PSEdition -eq "Core") {
Start-Process pwsh.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
} else {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
}

exit
}

#region Functions

function WriteInfo($message){
Write-Host $message
}

function WriteInfoHighlighted($message){
Write-Host $message -ForegroundColor Cyan
}

function WriteSuccess($message){
Write-Host $message -ForegroundColor Green
}

function WriteError($message){
Write-Host $message -ForegroundColor Red
}

function WriteErrorAndExit($message){
Write-Host $message -ForegroundColor Red
Write-Host "Press enter to continue ..."
Read-Host | Out-Null
Exit
}

#endregion

#region Ask for VHDs
WriteInfoHighlighted "Please select VHDx file(s)"
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
$VHDs = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $true;
Title="Please select VHDx file(s)"
}
$VHDs.Filter = "vhdx files (*.vhdx)|*.vhdx|All files (*.*)|*.*"
If($VHDs.ShowDialog() -eq "OK"){
WriteInfo "File $($VHDs.FileName) selected"
}
if (!$VHDs.FileName){
WriteErrorAndExit "VHDx was not selected... Exitting"
}
#endregion

#region ask for MSU packages
WriteInfoHighlighted "Please select msu packages you want to add to VHDx."
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
$msupackages = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $true;
Title="Please select msu packages you want to add to VHDx."
}
$msupackages.Filter = "msu files (*.msu)|*.msu|All files (*.*)|*.*"
If($msupackages.ShowDialog() -eq "OK"){
WriteInfoHighlighted "Following patches selected:"
foreach ($filename in $msupackages.FileNames){
WriteInfo "`t $filename"
}
}else{
WriteErrorAndExit "No update package selected, exitting"
}
#endregion

# region mount and patch VHD
foreach ($VHD in $VHDs) {
WriteInfoHighlighted "Patching VHD $($VHD.Filename)"
$Mount=Mount-VHD $Vhd.FileName -Passthru
#Grab letter
$DriveLetter=(Get-Disk -Number $Mount.Number |Get-Partition | Where-Object Driveletter).DriveLetter
#Patch
foreach ($msupackage in $msupackages){
Add-WindowsPackage -PackagePath $msupackage.filename -Path "$($DriveLetter):\"
}
#Dismount
$Mount | Dismount-VHD
}
#endregion

WriteSuccess "Job Done. Press enter to continue..."
Read-Host | Out-Null

0 comments on commit 0604f02

Please sign in to comment.