Last active
April 9, 2023 00:29
-
-
Save stknohg/ae03f8b6a72c6a05b4a5e4d4fe4624a7 to your computer and use it in GitHub Desktop.
EC2 Image BuilderでWindows Serverを日本語化するコンポーネント
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: windows-server-setup-japanese-ui | |
description: Install Japanese Language pack and Update UI configurations. | |
schemaVersion: 1.0 | |
parameters: | |
- S3BucketName: | |
type: string | |
default: 'your-bucket-name' | |
description: Set your S3 bucket name. | |
- S3BucketPath: | |
type: string | |
default: 'LanguagePack/WindowsServer2022/Microsoft-Windows-Server-Language-Pack_x64_ja-jp.cab' | |
description: Set your S3 key path for language packe .cab file. | |
phases: | |
- name: build | |
steps: | |
- name: DownloadLanguagePackStep | |
action: S3Download | |
inputs: | |
- source: s3://{{ S3BucketName }}/{{ S3BucketPath }} | |
destination: C:\Windows\TEMP\Microsoft-Windows-Server-Language-Pack_x64_ja-jp.cab | |
overwrite: true | |
- name: InstallLanguagePackStep | |
action: ExecutePowerShell | |
inputs: | |
commands: | |
- | | |
# Set configurations | |
$jpCabPath = 'C:\Windows\TEMP\Microsoft-Windows-Server-Language-Pack_x64_ja-jp.cab' | |
# Check if file exists | |
if (-not (Test-Path -LiteralPath $jpCabPath)) { | |
Write-Error ('Failed to download {0}.' -f $jpCabPath) | |
return | |
} | |
# Install language pack | |
try { | |
Write-Output 'Insall Language pack cab file...' | |
Write-Output (' {0}' -f $jpCabPath) | |
Add-WindowsPackage -Online -PackagePath $jpCabPath -LogPath (Join-Path -Path $env:TEMP 'dism.log') | |
} catch { | |
Write-Error $_ | |
return | |
} finally { | |
# Remove .cab | |
if (Test-Path -LiteralPath $jpCabPath) { | |
Write-Output 'Remove Language pack cab file...' | |
Remove-Item -LiteralPath $jpCabPath | |
} | |
} | |
# Set UI Language Settings | |
Write-Output 'Update language list...' | |
Set-WinUserLanguageList -LanguageList ja-JP, en-US -Force | |
# Set System local | |
Write-Output 'Update system locale...' | |
Set-WinSystemLocale -SystemLocale ja-JP | |
- name: RebootAfterLanguagePackInstalled | |
action: Reboot | |
inputs: | |
delaySeconds: 10 | |
- name: UpdateUIConfigurationsStep | |
action: ExecutePowerShell | |
inputs: | |
commands: | |
- | | |
# Update UI Language Settings | |
Write-Output 'Update UI language...' | |
Set-WinUILanguageOverride -Language ja-JP | |
Write-Output 'Update Input method...' | |
Set-WinDefaultInputMethodOverride -InputTip '0411:00000411' | |
# Set Location settings | |
Write-Output 'Set Location...' | |
Set-WinHomeLocation -GeoId 122 | |
Set-WinCultureFromLanguageListOptOut -OptOut $False | |
# Set Timezone | |
Write-Output 'Set Timezone...' | |
Set-TimeZone -Id 'Tokyo Standard Time' | |
- name: UpdateSysprepCconfigsStep | |
action: ExecutePowerShell | |
inputs: | |
commands: | |
- | | |
$xmlFiles = @() | |
# EC2 Launch v2 | |
if (Test-Path -LiteralPath 'C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml') { | |
$xmlFiles += 'C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml' | |
} | |
# EC2 Launch v1 | |
if (Test-Path -LiteralPath 'C:\ProgramData\Amazon\EC2-Windows\Launch\Sysprep\Unattend.xml') { | |
$xmlFiles += 'C:\ProgramData\Amazon\EC2-Windows\Launch\Sysprep\Unattend.xml' | |
} | |
foreach ($x in $xmlFiles) { | |
Write-Output ('Update {0}...' -f $x) | |
# Backup Unattend.xml | |
Copy-Item -LiteralPath $x -Destination "${x}.orig" -Force | |
# Update Unattend.xml | |
$xmlDoc = [xml](Get-Content -LiteralPath $x -Raw) | |
# Update Timezone | |
$xmlDoc.unattend.settings.component | Where-Object { $_.name -eq 'Microsoft-Windows-Shell-Setup' } | ForEach-Object { | |
$_.TimeZone = 'Tokyo Standard Time' | |
} | |
# Update Launguage, Locale | |
$xmlDoc.unattend.settings.component | Where-Object { $_.name -eq 'Microsoft-Windows-International-Core' } | ForEach-Object { | |
$_.InputLocale = 'ja-JP' | |
$_.SystemLocale = 'ja-JP' | |
$_.UILanguage = 'ja-JP' | |
$_.UserLocale = 'ja-JP' | |
} | |
$xmlDoc.Save($x) | |
} | |
- name: ApplyWindowsUpdateStep | |
action: UpdateOS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
詳細は以下の記事で公開してます。