Update files

Updated the Test-CompatibleImage function to compare against a desired version, which is useful for determining if the Specialize pass needs to be added to the unattended answer file
This commit is contained in:
CodingWonders 2024-02-09 20:03:05 +01:00
parent 42d13ad735
commit 2fbe40a3ee
3 changed files with 62 additions and 32 deletions

View File

@ -18,28 +18,23 @@ function Test-CompatibleImage() {
<#
.SYNOPSIS
Checks the version of a Windows image and determines whether or not it is compatible depending on the Major property
Checks the version of a Windows image and determines whether or not it is compatible with a specific feature depending on a desired version
.PARAMETER imgVersion
The version of the Windows image
.PARAMETER Name
imgVersion - The version of the Windows image
desiredVersion - The version to compare the image version with
#>
param
(
[Parameter(Mandatory = $true)] [string] $imgVersion
[Parameter(Mandatory = $true, Position=0)] [string] $imgVersion,
[Parameter(Mandatory = $true, Position=1)] [Version] $desiredVersion
)
try {
$version = [Version]$imgVersion
if ($version.Major -ge 10)
{
return $True
}
else
{
return $False
}
return $version -ge $desiredVersion
} catch {
return $False
}
@ -247,7 +242,7 @@ function Remove-FileOrDirectory([string] $pathToDelete, [string] $mask = "", [sw
foreach($itemToDelete in $itemsToDelete)
{
$status = "Deleteing $($itemToDelete)"
$status = "Deleting $($itemToDelete)"
Write-Progress -Activity "Removing Items" -Status $status -PercentComplete ($counter++/$itemsToDelete.Count*100)
if (Test-Path -Path "$($itemToDelete)" -PathType Container)
@ -321,7 +316,7 @@ function New-Unattend {
<unattend xmlns="urn:schemas-microsoft-com:unattend"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<#REPLACEME#>
<settings pass="auditUser">
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
@ -362,6 +357,26 @@ function New-Unattend {
</settings>
</unattend>
'@
$specPass = @'
<settings pass="specialize">
<component name="Microsoft-Windows-SQMApi" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CEIPEnabled>0</CEIPEnabled>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ConfigureChatAutoInstall>false</ConfigureChatAutoInstall>
</component>
</settings>
'@
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,22000,1))) -eq $false)
{
# Replace the placeholder text with an empty string to make it valid for Windows 10 Setup
$unattend = $unattend.Replace("<#REPLACEME#>", "").Trim()
}
else
{
# Replace the placeholder text with the Specialize pass
$unattend = $unattend.Replace("<#REPLACEME#>", $specPass).Trim()
}
$unattend | Out-File -FilePath "$env:temp\unattend.xml" -Force
}

View File

@ -60,7 +60,7 @@ public class PowerManagement {
$imgVersion = (Get-WindowsImage -ImagePath $mountDir\sources\install.wim -Index $index).Version
# Detect image version to avoid performing MicroWin processing on Windows 8 and earlier
if ((Test-CompatibleImage $imgVersion) -eq $false)
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,10240,0))) -eq $false)
{
$msg = "This image is not compatible with MicroWin processing. Make sure it isn't a Windows 8 or earlier image."
$dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers."

View File

@ -10,7 +10,7 @@
Author : Chris Titus @christitustech
Runspace Author: @DeveloperDurp
GitHub : https://github.com/ChrisTitusTech
Version : 24.02.08
Version : 24.02.09
#>
param (
[switch]$Debug,
@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms
# Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.version = "24.02.08"
$sync.version = "24.02.09"
$sync.configs = @{}
$sync.ProcessRunning = $false
@ -626,28 +626,23 @@ function Test-CompatibleImage() {
<#
.SYNOPSIS
Checks the version of a Windows image and determines whether or not it is compatible depending on the Major property
Checks the version of a Windows image and determines whether or not it is compatible with a specific feature depending on a desired version
.PARAMETER imgVersion
The version of the Windows image
.PARAMETER Name
imgVersion - The version of the Windows image
desiredVersion - The version to compare the image version with
#>
param
(
[Parameter(Mandatory = $true)] [string] $imgVersion
[Parameter(Mandatory = $true, Position=0)] [string] $imgVersion,
[Parameter(Mandatory = $true, Position=1)] [Version] $desiredVersion
)
try {
$version = [Version]$imgVersion
if ($version.Major -ge 10)
{
return $True
}
else
{
return $False
}
return $version -ge $desiredVersion
} catch {
return $False
}
@ -855,7 +850,7 @@ function Remove-FileOrDirectory([string] $pathToDelete, [string] $mask = "", [sw
foreach($itemToDelete in $itemsToDelete)
{
$status = "Deleteing $($itemToDelete)"
$status = "Deleting $($itemToDelete)"
Write-Progress -Activity "Removing Items" -Status $status -PercentComplete ($counter++/$itemsToDelete.Count*100)
if (Test-Path -Path "$($itemToDelete)" -PathType Container)
@ -929,7 +924,7 @@ function New-Unattend {
<unattend xmlns="urn:schemas-microsoft-com:unattend"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<#REPLACEME#>
<settings pass="auditUser">
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
@ -970,6 +965,26 @@ function New-Unattend {
</settings>
</unattend>
'@
$specPass = @'
<settings pass="specialize">
<component name="Microsoft-Windows-SQMApi" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CEIPEnabled>0</CEIPEnabled>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ConfigureChatAutoInstall>false</ConfigureChatAutoInstall>
</component>
</settings>
'@
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,22000,1))) -eq $false)
{
# Replace the placeholder text with an empty string to make it valid for Windows 10 Setup
$unattend = $unattend.Replace("<#REPLACEME#>", "").Trim()
}
else
{
# Replace the placeholder text with the Specialize pass
$unattend = $unattend.Replace("<#REPLACEME#>", $specPass).Trim()
}
$unattend | Out-File -FilePath "$env:temp\unattend.xml" -Force
}
@ -3305,7 +3320,7 @@ public class PowerManagement {
$imgVersion = (Get-WindowsImage -ImagePath $mountDir\sources\install.wim -Index $index).Version
# Detect image version to avoid performing MicroWin processing on Windows 8 and earlier
if ((Test-CompatibleImage $imgVersion) -eq $false)
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,10240,0))) -eq $false)
{
$msg = "This image is not compatible with MicroWin processing. Make sure it isn't a Windows 8 or earlier image."
$dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers."