зеркало из https://github.com/microsoft/MSLab.git
added PatchParentDisks script
This commit is contained in:
Родитель
f9372442db
Коммит
0604f027d1
|
@ -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){
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче