Skip to content

Instantly share code, notes, and snippets.

@manelrodero
Last active July 2, 2022 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manelrodero/13a67fd84aa7c4f4c6004832eacbd126 to your computer and use it in GitHub Desktop.
Save manelrodero/13a67fd84aa7c4f4c6004832eacbd126 to your computer and use it in GitHub Desktop.
Script to copy all the software needed to implement Johan Arwidmark's Hydration Kit to Deployment Share
<#
.SYNOPSIS
Script to copy all the software needed to implement Johan Arwidmark's Hydration Kit to Deployment Share.
.DESCRIPTION
This script copies all the software needed to implement Johan Arwidmark's Hydration Kit
(Windows Server, SQL Server, Configuration Manager, Windows ADK, etc.) to MDT Deployment Share.
.NOTES
Created : 1 July 2022
Modified : 2 July 2022
Version : 1.2
Author : Manel Rodero
Twitter : @manelrodero
Blog : https://www.manelrodero.com/
Disclaimer:
This script has only been tested with PowerShell 5.1.
This script is provided "AS IS" with no warranties, confers no rights and is not supported by the author.
.PARAMETER HydrationKitBase
Specifies the directory where the installers have been downloaded.
It is recommended that you do not use a directory with a name that contains spaces.
.PARAMETER CMLab
Specifies the base directory where the Hydration Kit share is installed (for example C:\Shares\CMLab).
DO NOT specify the DS directory (for example C:\Shares\CMLab\DS)!
.PARAMETER UseEvaluation
Specifies whether you want to use evaluation versions of Microsoft products (Windows, SQL Server, Configuration Manager)
The default option is $true.
.PARAMETER SQLISOName
Specifies the name of the licensed SQL Server 2019 ISO file.
.PARAMETER CMISOName
Specifies the name of the licensed Configuration Manager CB 2203 ISO file.
.EXAMPLE
.\Copy-SoftwareToHydrationKitDS.ps1 -HydrationKitBase "D:\HydrationKitBase" -CMLab "C:\Shares\CMLab"
Copies all required software for Hydration Kit to C:\Shares\CMLab using evaluation versions of
Microsoft Windows, SQL Server, and Configuration Manager.
.EXAMPLE
$SQLISOName = "SW_DVD9_NTRL_SQL_Svr_Standard_Edtn_2019Dec2019_64Bit_English_OEM_VL_X22-22109.ISO"
$CMISOName = "SW_DVD5_MEM_ConfigMgrClt_ML_2203_MultiLang_ConfMgr_MLF_X23-12967.ISO"
.\Copy-SoftwareToHydrationKitDS.ps1 -HydrationKitBase "D:\HydrationKitBase" -CMLab "C:\Shares\CMLab" -UseEvaluation $false -SQLISOName $SQLISOName -CMISOName $CMISOName
Copies all required software for Hydration Kit to C:\Shares\CMLab using licensed versions of
Microsoft Windows, SQL Server and Configuration Manager,
#>
#Requires -Version 5.1
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[parameter(Mandatory=$true, HelpMessage="Specify the directory to which the software has been downloaded.")]
[ValidateNotNullOrEmpty()]
[string]$HydrationKitBase,
[parameter(Mandatory=$true, HelpMessage="Specify the base directory where the Hydration Kit share is installed.")]
[ValidateNotNullOrEmpty()]
[string]$CMLab,
[parameter(Mandatory=$false, HelpMessage="Specify whether you want to use the evaluation version of Microsoft products.")]
[ValidateSet($false,$true)]
[boolean]$UseEvaluation = $true,
[parameter(Mandatory=$false, HelpMessage="Specify the name of the licensed SQL Server 2019 ISO file.")]
[ValidatePattern("\.iso$")]
[string]$SQLISOName,
[parameter(Mandatory=$false, HelpMessage="Specify the name of the licensed Configuration Manager CB 2203 ISO file.")]
[ValidatePattern("\.iso$")]
[string]$CMISOName
)
# Function to color the text
Function Write-Color ($Color, $Text) {
$t = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = $Color
Write-Output $Text
$host.ui.RawUI.ForegroundColor = $t
}
# Verify that the Hydration Kit base directory exist
If (!(Test-Path -Path $HydrationKitBase)) {
Write-Warning "The Hydration Kit base directory does not exist. Use the 'Download-SoftwareForHydrationKit.ps1' script to download the kit and the necessary software. Aborting..."
Break
}
# Verify that the base directory where the Hydration Kit share exist
If (!(Test-Path -Path $CMLab)) {
Write-Warning "Hydration Kit Deployment Share doesn't exist. Use the 'New-HydrationKitSetup.ps1' script to create it. Aborting..."
Break
}
# Directory structure
$HKDownloads = "$HydrationKitBase\Downloads"
$HKSetup = "$HydrationKitBase\Setup"
$HKTemp = "$HydrationKitBase\Temp"
# Verify Evaluation vs License
if ($UseEvaluation) {
$SQLISOName = "SQLServer2019-x64-ENU.iso"
$SQLISOPath = "$HKDownloads\$SQLISOName"
$CMEXEName = "MEM_ConfigManager_2203_Eval.exe"
$CMEXEPath = "$HKDownloads\$CMEXEName"
} else {
if ($SQLISOName) {
$SQLISOPath = "$HKDownloads\$SQLISOName"
} else {
Write-Warning "You must specify the name of the SQL Server 2019 ISO file. Aborting..."
Break
}
if ($CMISOName) {
$CMISOPath = "$HKDownloads\$CMISOName"
} else {
Write-Warning "You must specify the name of the Configuration Manager 2203 ISO file. Aborting..."
Break
}
}
# ISO Validation
If (!(Test-Path -Path $SQLISOPath)) {
Write-Warning "ISO File: $SQLISOPath does not exist. Aborting..."
Break
}
If ($UseEvaluation -and !(Test-Path -Path $CMEXEPath)) {
Write-Warning "EXE File: $CMEXEPath does not exist. Aborting..."
Break
}
If (!($UseEvaluation) -and !(Test-Path -Path $CMISOPath)) {
Write-Warning "ISO File: $CMISOPath does not exist. Aborting..."
Break
}
# Windows Server 2022 Reference Image
Write-Color "Green" "Copying Windows Server 2022 Reference Image 'REFWS2022-001.wim' ..."
Copy-Item -Path "$HKSetup\ReferenceWIM\REFWS2022-001.wim" -Destination "$CMLab\DS\Operating Systems\WS2022" -Force
# Allow installation of .NET Framework 3.5 if the VM does not have Internet access
Write-Color "Cyan" "Allowing offline install of .NET Framework 3.5 ..."
Copy-Item -Path "$HKSetup\ReferenceWIM\microsoft-windows-netfx3-ondemand-package~31bf3856ad364e35~amd64~~.cab" -Destination "$CMLab\DS\Operating Systems\WS2022\sources\sxs" -Force
# BGInfo
Write-Color "Green" "Copying BGInfo ..."
Expand-Archive -Path "$HKDownloads\BGInfo.zip" -DestinationPath "$HKTemp"
Copy-Item -Path "$HKTemp\Bginfo.exe" -Destination "$CMLab\DS\Applications\Install - BGInfo\Source" -Force
Remove-Item -Path "$HKTemp\*.*"
# Windows ADK 11
Write-Color "Green" "Copying Windows ADK 11 ..."
Copy-Item -Path "$HKSetup\Windows ADK 11\*" -Destination "$CMLab\DS\Applications\Install - Windows ADK 11\Source" -Recurse -Force
Write-Color "Green" "Copying Windows ADK 11 WinPE Addon..."
Copy-Item -Path "$HKSetup\Windows ADK 11 WinPE Addon\*" -Destination "$CMLab\DS\Applications\Install - Windows ADK 11 WinPE Addon\Source" -Recurse -Force
# SQL Server 2019 Standard
if ($UseEvaluation) { $SQLText = "(Evaluation)" } else { $SQLText = "(Licensed)" }
Write-Color "Green" "Copying SQL Server 2019 $SQLText ..."
Mount-DiskImage -ImagePath $SQLISOPath | Out-Null
$ISOImage = Get-DiskImage -ImagePath $SQLISOPath | Get-Volume
$ISODrive = [string]$ISOImage.DriveLetter+":"
Copy-Item -Path "$ISODrive\*" -Destination "$CMLab\DS\Applications\Install - SQL Server 2019 Standard\Source" -Recurse -Force
Dismount-DiskImage -ImagePath $SQLISOPath | Out-Null
# SQL Server 2019 Cumulative Update
Write-Color "Green" "Copying SQL Server 2019 Cumulative Update ..."
New-Item -Type Directory -Path "$CMLab\DS\Applications\Install - SQL Server 2019 Standard\Source" -Name "Updates" -Force | Out-Null
Copy-Item -Path "$HKDownloads\SQLServer2019-KB5011644-x64.exe" -Destination "$CMLab\DS\Applications\Install - SQL Server 2019 Standard\Source\Updates" -Force
# SQL Server Management Studio
Write-Color "Green" "Copying SQL Server Management Studio ..."
Copy-Item -Path "$HKDownloads\SSMS-Setup-ENU.exe" -Destination "$CMLab\DS\Applications\Install - SQL Server Management Studio" -Force
# SQL Server Reporting Services
Write-Color "Green" "Copying SQL Server Reporting Services ..."
Copy-Item -Path "$HKDownloads\SQLServerReportingServices.exe" -Destination "$CMLab\DS\Applications\Install - SQL Server 2019 Reporting Services\Source" -Force
# Microsoft Configuration Manager
if ($UseEvaluation) {
Write-Color "Green" "Copying Configuration Manager CB 2203 (Evaluation) ..."
Start-Process -FilePath "$CMEXEPath" -ArgumentList "/auto `"$CMLab\DS\Applications\Install - ConfigMgr\Source`"" -Wait
} else {
Write-Color "Green" "Copying Configuration Manager CB 2203 (Licensed) ..."
Mount-DiskImage -ImagePath $CMISOPath | Out-Null
$ISOImage = Get-DiskImage -ImagePath $CMISOPath | Get-Volume
$ISODrive = [string]$ISOImage.DriveLetter+":"
Copy-Item -Path "$ISODrive\*" -Destination "$CMLab\DS\Applications\Install - ConfigMgr\Source" -Recurse -Force
Dismount-DiskImage -ImagePath $CMISOPath | Out-Null
}
# Microsoft Configuration Manager Pre-requisites
Write-Color "Green" "Copying Configuration Manager Pre-requisites ..."
Start-Process -FilePath "$CMLab\DS\Applications\Install - ConfigMgr\Source\SMSSETUP\BIN\X64\setupdl.exe" -ArgumentList "`"$CMLab\DS\Applications\Install - ConfigMgr\PreReqs`"" -Wait
# Microsoft Deployment Toolkit
Write-Color "Green" "Copying Microsoft Deployment Toolkit ..."
Copy-Item -Path "$HKDownloads\MicrosoftDeploymentToolkit_x64.msi" -Destination "$CMLab\DS\Applications\Install - MDT" -Force
# SQL Server Express
Write-Color "Green" "Copying SQL Server Express ..."
Copy-Item -Path "$HKDownloads\SQLEXPR_x64_ENU.exe" -Destination "$CMLab\DS\Applications\Install - SQL Server 2019 Express\Source" -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment