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 1157 times Last modified on Tuesday, 16 January 2018 13:20
  1. Comments (0)

  2. Add yours
There are no comments posted here yet

Leave your comments

Posting comment as a guest.
0 Characters
Attachments (0 / 3)
Share Your Location

Recent Posts

  • Yet Another Windows 10 Optimization Script
    As a reminder, Microsoft will be ending support for Windows 7 SP1 on January 14, 2020. I've had multiple enterprise…
    Written on Monday, 25 June 2018 16:09
  • Automating Dell BIOS Configuration Using MDT
    It’s been a busy couple of weeks for me, so I’m slowly going through a backlog of things to cover.…
    Written on Thursday, 21 June 2018 08:11
  • Configuring HP BIOS Using MDT
    This is the second post in my series that explores one of the most common questions I’ve been asked from…
    Written on Tuesday, 19 June 2018 09:54
  • BIOS to UEFI - The Easy Way: MBR2GPT
    This article is the first blog post in a series I'll write over the coming days that will provide a…
    Written on Monday, 11 June 2018 17:08
  • Force LAPS Password Reset during MDT OSD
    My customers often send me exciting cases. This particular one is especially interesting because it is common in infrastructures that…
    Written on Friday, 08 June 2018 10:10
  • Localizing Inbox Apps during OSD
    As a reader of this blog, I suspect that most of you, like me, are frequenting Twitter. And I bet…
    Written on Monday, 04 June 2018 18:18