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

  2. Add yours
This comment was minimized by the moderator on the site

Hi anton ,
I tried the above in 1803 , it was ok in 1709 .
I cant see language bar to choose the language .
could you help please
Thanks

raj
There are no comments posted here yet

Leave your comments

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

Recent Posts

  • 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 Corrupted Store Apps
    A few days ago I began experiencing issues with built-in Windows apps where various apps would flash open and close…
    Written on Wednesday, 14 August 2019 13:36
  • 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
  • Windows 10 1903: Useful Resources for IT Professionals
    Windows 10, version 1903 is now available via Windows Update for Business, Windows Server Update Services (WSUS) and the Volume…
    Written on Friday, 07 June 2019 11:21
  • Windows 10 1903 Built-In Apps: What to Keep
    The development of the Windows 10, version 1903 is finished and the update is now available for download from Visual…
    Written on Monday, 03 June 2019 06:59