Monday, 15 January 2018 12:36

How to Automate Input Preferences during OSD

Written by
Rate this item
(0 votes)

image

A few days ago I stumbled upon a question on the Microsoft Deployment Toolkit (MDT) forum where a user asked for guidance on how to install support for additional keyboard layouts using MDT. This post explains how you can add additional keyboards in Windows during OSD.

From my past blog posts, I knew that you can configure various regional and language settings using intl.cpl and an xml based answer file. Intl.cpl can be used to set default locale, input locale, GeoID & location preferences and user interface language-related settings. I am not going to go into a lot of detail as it is beyond the scope of today's post; visit support.microsoft.com for a detailed description of the intl.cpl feature set. .

To install support for additional keyboard layouts during OSD you need to...
  • Create an answer file that contains the regional settings items you wish to configure
  • Save it (for example, as C:\temp\MUI.xml)
  • Apply the answer file settings using:
    control.exe intl.cpl,,/f:"C:\temp\MUI.xml"

I wanted to wrap the configure functionality into an easy to use PowerShell script. As per usual, I am not a fan of reinventing the wheel - there is literally no reason to waste time and develop a solution that might already be available on TechNet or an IT pro's blog. However, a quick Google search yielded no results that provided clear guidance on, so I quickly cobbled together a sample script. Below is the end result:

# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("LogPath")  
$logFile = "$logPath\$($myInvocation.MyCommand).log"

# Create Logfile
Write-Output "Create Logfile" > $logFile
 
Function Logit($TextBlock1){
	$TimeDate = Get-Date
	$OutPut = "$ScriptName - $TextBlock1 - $TimeDate"
	Write-Output $OutPut >> $logFile
}

# Start Main Code Here

$ScriptName = $MyInvocation.MyCommand

# Get data
$CountryCode = ($env:COMPUTERNAME).Substring(0,2)
$RunningFromFolder = $MyInvocation.MyCommand.Path | Split-Path -Parent 
. Logit "Running from $RunningFromFolder"
. Logit "CountryCode variable = $CountryCode"

# Create c:\temp if doesn't exist
IF (!(Test-Path "C:\temp")) {
    New-Item -ItemType Directory -Force -Path "C:\temp"
}

#Generate XML
. Logit "Generating MUI.xml file..."
#https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10)
$xml = @()

$xml = '<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
 
    <!-- user list -->
    <gs:UserList>
        <gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
    </gs:UserList>

   <!-- input preferences -->
    <gs:InputPreferences>
        <gs:InputLanguageID Action="add" ID="0407:00000407"/>
    </gs:InputPreferences> </gs:GlobalizationServices>' $xml | Out-File "C:\temp\MUI.xml" #Apply MUI settings $ErrorActionPreference = 'SilentlyContinue' . Logit "Applying MUI settings ... " C:\Windows\System32\control.exe "intl.cpl,,/f:""c:\temp\MUI.xml""" | Out-Null Exit 0

Setting this up is dead simple if you are using MDT. Simply save this script into your deployment share, adjust keyboard ID(s) using this reference table and add a Run PowerShell script step to your TS. That's it! 

Below is a somewhat more advanced example which uses computer naming convention to determine machine's location (Germany or Swiss) and to install additional keyboards depending on the result:

# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("LogPath")  
$logFile = "$logPath\$($myInvocation.MyCommand).log"

# Create Logfile
Write-Output "Create Logfile" > $logFile
 
Function Logit($TextBlock1){
	$TimeDate = Get-Date
	$OutPut = "$ScriptName - $TextBlock1 - $TimeDate"
	Write-Output $OutPut >> $logFile
}

# Start Main Code Here

$ScriptName = $MyInvocation.MyCommand

# Get data
$CountryCode = ($env:COMPUTERNAME).Substring(0,2)
$RunningFromFolder = $MyInvocation.MyCommand.Path | Split-Path -Parent 
. Logit "Running from $RunningFromFolder"
. Logit "CountryCode variable = $CountryCode"

# Create c:\temp if doesn't exist
IF (!(Test-Path "C:\temp")) {
    New-Item -ItemType Directory -Force -Path "C:\temp"
}

#Generate XML
. Logit "Generating MUI.xml file..."
#https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10)
$xml = @()
$xml = '<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">

<!-- user list -->
<gs:UserList>
<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
</gs:UserList>
'
If ($CountryCode -eq "CH") {
$xml += '
<!-- input preferences -->
<gs:InputPreferences>
<gs:InputLanguageID Action="add" ID="100c:0000100c"/>
<gs:InputLanguageID Action="add" ID="0810:00000410"/>
<gs:InputLanguageID Action="add" ID="0807:00000807"/>
</gs:InputPreferences>
'
}
Else {
$xml += '
<!-- input preferences -->
<gs:InputPreferences>
<gs:InputLanguageID Action="add" ID="0407:00000407"/>
</gs:InputPreferences>
'
}
$xml += '</gs:GlobalizationServices>' $xml | Out-File "C:\temp\MUI.xml" #Apply MUI settings $ErrorActionPreference = 'SilentlyContinue' . Logit "Applying MUI settings ... " C:\Windows\System32\control.exe "intl.cpl,,/f:""c:\temp\MUI.xml""" | Out-Null Exit 0
Read 392 times Last modified on Tuesday, 16 January 2018 13:20

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Recent Posts

  • Automating Multi-node Tableau Server Environment
    After a few weeks off, I am delighted to announce that I have returned full time, once again delivering somewhat…
    Written on Monday, 19 February 2018 11:01
  • The Case of Missing TPM P@ssword
    As my regular blog readers will be aware (yes, all three of you), there is something increasingly traditional about me…
    Written on Thursday, 25 January 2018 10:04
  • The Case of "Just a Moment..."
    A key part of any complete end-to-end deployment project is analysis of the resulting logs to identify root causes for…
    Written on Tuesday, 16 January 2018 12:57
  • How to Automate Input Preferences during OSD
    A few days ago I stumbled upon a question on the Microsoft Deployment Toolkit (MDT) forum where a user asked…
    Written on Monday, 15 January 2018 12:36
  • Disabling Cortana Voice Support during OOBE
    Yesterday I came across a Twitter thread in which multiple users detailed their beef with the revamped setup experience of…
    Written on Tuesday, 12 December 2017 10:04
  • Fixing "Windows update reboot is pending" during OSD
    Automated OS deployment became common as IT professionals install systems using tools like Microsoft Deployment Toolkit or System Center Configuration…
    Written on Tuesday, 28 November 2017 08:44