Skip to content

Instantly share code, notes, and snippets.

@cdgco
Last active April 22, 2024 20:18
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 cdgco/7e43c0211939eae5fbe6389835bdf979 to your computer and use it in GitHub Desktop.
Save cdgco/7e43c0211939eae5fbe6389835bdf979 to your computer and use it in GitHub Desktop.
Choose Task Sequence UI
<#
.SYNOPSIS
This script launches UI++ with dynamic choices based on Task Sequence Variables.
.DESCRIPTION
The script sets up the environment for a UI++ execution and dynamically modifies an XML template based on Task Sequence Variables.
.NOTES
- Author: Carter Roeser
- Last Updated: 2024-03-12
- Please ensure PowerShell Execution Policy allows script execution and that all paths and dependencies are correctly configured in your environment.
- Designed to be used in an MECM task sequence, where automation of driver installation is crucial. Will fail if the Task Sequence Environment COM object is not available.
- Make sure to adjust the script paths and environment variables according to your specific deployment environment.
#>
# Setup TSEnv - Read and Write default Task Sequence Variables
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$choices = $TSEnv.Value('ChooseTS___OptionsList')
$choicesOrder = $TSEnv.Value('ChooseTS___OptionsOrder')
$choicesKeys = $choicesOrder -split '~!~'
$tsVars = ""
foreach ($i in 0..($choicesKeys.Length - 1)) {
$tsVars += "<Action Type=`"TSVar`" Name=`"ChooseTS_$($choicesKeys[$i])`">Split(`"%TSChoice%`", `"`~!~`"`)($i)</Action>`n"
}
$templateContent = Get-Content "$PSScriptRoot\ChooseTemplate.xml" -Raw
$updatedContent = $templateContent -replace '<TSVarPlaceholder />', $tsVars
$updatedContent = $$updatedContent -replace '<ChoicesPlaceholder />', $choices
$outputPath = "$Env:SystemDrive\UI++\ChooseTemplate.xml"
# Ensure the UI++ directory exists
if (-not (Test-Path "$Env:SystemDrive\UI++")) {
New-Item -Path "$Env:SystemDrive\UI++" -ItemType Directory
}
# Save the modified content to the output path
$updatedContent | Set-Content $outputPath
# Run UI++ with the XML
Start-Process -Wait x64/UI++64.exe /config:"$Env:SystemDrive\UI++\ChooseTemplate.xml"
<?xml version="1.0" encoding="utf-8"?>
<UIpp Title="CJRoeser.com OSD" Color="#5fa5fa">
<Actions>
<Action Type="TSVar" Name="UIPlusPlusStarted">"True"</Action>
<ActionGroup Name="Choose Task Sequence" Condition='"%ChooseTS_Name%" = ""' >
<Action Type="Input" Name="ChooseTaskSequence" Title="Welcome" ShowCancel="True">
<InputInfo>Choose Task Sequence by CJRoeser.com.</InputInfo>
<InputInfo NumberofLines="2">If you are not expecting this screen, please click cancel and contact your help desk.</InputInfo>
<InputChoice Variable="TSChoice" Default="Windows 11 Domain Desktop" Sort="False" Question="Choose Task Sequence" Required="True" AutoComplete="False">
<!-- ChoicesPlaceholder will be replaced via PowerShell on TS run. -->
<ChoicesPlaceholder />
</InputChoice>
</Action>
<!-- TSVarPlaceholder will be replaced via PowerShell on TS run. -->
<TSVarPlaceholder />
</ActionGroup>
<Action Type="Input" Name="SetupTaskSequence" Title="Configure System" ShowCancel="True" ShowBack="True">
<InputText RegEx=".{3,15}" Variable="OSDComputerName" Question="System Name" Required="True"/>
<InputInfo>Name must be between 3 and 15 characters long.</InputInfo>
</Action>
<ActionGroup Name="Preflight" Condition='NOT "%EnablePreflight%" = "No"'>
<Action Type="DefaultValues" ValueTypes="Asset,TPM,Network" ShowProgress="True" />
<Action Type="Preflight" Title="Preflight checks" ShowOnFailureOnly="False" ShowBack="True" ShowCancel="True" Timeout="180" TimeoutAction="ContinueOnWarning">
<!-- Warn if AC Power is not connected -->
<Check Text="AC Power" Description="System connected to AC Power" WarnDescription="Please ensure that the system is connected to AC Power." WarnCondition='"%XOnBattery%" = "False"' />
<!-- Fail if not connected to wired network -->
<Check Text="Wired Network" Description="System connected to Wired Network" ErrorDescription="Please ensure that the system has a wired network connection" CheckCondition='"%XWiredLANConnected%" = "True"' />
<!-- Warn if UEFI not enabled -->
<Check Text="UEFI Enabled" Description="UEFI Boot enabled in BIOS" WarnCondition='"%XSystemUEFI%" = "True"' WarnDescription="For security purposes, UEFI should be enabled."/>
<!-- Warn if Secure Boot not enabled -->
<Check Text="Secure Boot Enabled" Description="Secure Boot enabled in BIOS" WarnCondition='"%XSystemSecureBoot%" = "True"' WarnDescription="For security purposes, Secure Boot should be enabled."/>
<!-- Fail if TPM is available but not enabled -->
<Check Text="TPM Enabled" Description="TPM Chip enabled in BIOS" CheckCondition='"%XTPMEnabled%" = "True"' ErrorDescription="For security purposes, TPM should be enabled." />
</Action>
</ActionGroup>
<Action Type="TSVar" Name="UIPlusPlusFinished">"True"</Action>
</Actions>
</UIpp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment