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 15395 times Last modified on Tuesday, 16 January 2018 13:20

Recent Posts

  • Windows 10 21H2 Built-In Apps: What to Keep
    The development of the Windows 10, version 21H2 is finished and the update will soon be available for download from…
    Written on Wednesday, 20 October 2021 11:41
  • Group Policy Changes in Windows 10 21H2
    As Windows 10, version 21H2 update development winds down, Microsoft is now preparing for the final release of the Windows…
    Written on Wednesday, 20 October 2021 07:20
  • Group Policy Changes in Windows 10 20H1 Preview
    As Windows 10 Vibranium Update (20H1) development winds down, Microsoft is now beginning the phase of checking in the final…
    Written on Tuesday, 14 January 2020 04:51
  • An alternative ESU MAK Activation Solution
    This blog post was shared with me by a colleague of mine, Daniel Dorner, a Microsoft Premier Field Engineer. It’s…
    Written on Wednesday, 04 December 2019 21:04
  • The Case of Missing UE-V Templates
    My customers often deal with unexpected Windows behavior and this case is no different. This particular one is especially interesting…
    Written on Tuesday, 03 September 2019 12:20
  • The Case of Changing Default Printer
    While I sometimes long for the day when I no longer have to deal with unexpected Windows 10 behavior, there’s…
    Written on Wednesday, 14 August 2019 20:36