Skip to content

Instantly share code, notes, and snippets.

@mkht
Created October 6, 2019 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkht/2efd8c057902568a427e224c0260f5ef to your computer and use it in GitHub Desktop.
Save mkht/2efd8c057902568a427e224c0260f5ef to your computer and use it in GitHub Desktop.
Windows PE 10 バージョン1809の日本語化ISOを作成するスクリプト
<######################################################
# Windows PE 作成スクリプト
#######################################################>
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
$script:WorkDir = Join-Path $PSScriptRoot '\Work'
if (Test-Path $script:WorkDir -PathType Container -ErrorAction Ignore) {
Remove-Item $script:WorkDir -Force -Recurse
}
$null = New-Item $script:WorkDir -ItemType Directory -Force
Set-Location $script:WorkDir
# ============================
# パラメータ
# ============================
$script:Architecture = 'amd64'
$script:OutputFileName = 'WinPE.iso'
# ============================
# 必要なファイルをチェック
# ============================
@(
'efisys_noprompt.bin', # WindowsインストールDVDの efi\microsoft\boot フォルダ内に存在
'startnet.cmd'
) | % {
if (-not (Test-Path (Join-Path $PSScriptRoot $_) -ErrorAction Ignore)) {
throw ('{0} が見つかりません' -f $_)
}
}
# ============================
# Windows ADK & PE インストール
# ============================
# インストール済みかどうかチェック
$IsWinPEInstalled = [bool](Get-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots\10.0.17763.0\Installed Options' -ErrorAction Ignore | select -ExpandProperty 'OptionId.WindowsPreinstallationEnvironment')
if (-not $IsWinPEInstalled) {
# ダウンロード ADK & PE (バージョン1809)
Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?linkid=2026036' -OutFile 'adksetup.exe'
Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?linkid=2022233' -OutFile 'adkwinpesetup.exe'
# インストール ADK
$p1 = Start-Process -Wait -FilePath 'adksetup.exe' -ArgumentList '/features OptionId.DeploymentTools /q /norestart' -PassThru
if ($p1.ExitCode -ne 0) {
throw 'Install Windows ADK failed.'
}
else {
Write-Host 'Install Windows ADK Completed.'
}
# インストール PE
$p2 = Start-Process -Wait -FilePath 'adkwinpesetup.exe' -ArgumentList '/q /norestart' -PassThru
if ($p2.ExitCode -ne 0) {
throw 'Install Windows PE failed.'
}
else {
Write-Host 'Install Windows PE Completed.'
}
}
# ============================
# 環境変数設定
# ============================
$WinKitsRoot = Get-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots' | select -ExpandProperty 'KitsRoot10' -ErrorAction Ignore
$DeployMentToolsRoot = Join-Path $WinKitsRoot 'Assessment and Deployment Kit\Deployment Tools\amd64'
$env:WinPERoot = Join-Path $WinKitsRoot 'Assessment and Deployment Kit\Windows Preinstallation Environment'
$env:DISMRoot = Join-Path $DeployMentToolsRoot '\DISM'
$env:BCDBootRoot = Join-Path $DeployMentToolsRoot '\BCDBoot'
$env:ImagingRoot = Join-Path $DeployMentToolsRoot '\Imaging'
$env:OSCDImgRoot = Join-Path $DeployMentToolsRoot '\Oscdimg'
$env:WdsmcastRoot = Join-Path $DeployMentToolsRoot '\Wdsmcast'
$AddToPathList = @(
$env:WinPERoot
$env:DISMRoot
$env:BCDBootRoot
$env:ImagingRoot
$env:OSCDImgRoot
$env:WdsmcastRoot
)
$env:path = ([string[]](($env:path -split ';') + $AddToPathList) | Select-Object -Unique) -join ';'
# ============================
# Windows PE 作成
# ============================
copype $script:Architecture .\WinPE
try {
dism /mount-image /imagefile:.\WinPE\media\sources\boot.wim /index:1 /mountdir:.\WinPE\mount
# PXEブート(BIOS)用ファイル
Copy-Item .\WinPE\mount\Windows\Boot\PXE\bootmgr.exe .\WinPE\media\
Copy-Item .\WinPE\mount\Windows\Boot\PXE\pxeboot.n12 .\WinPE\media\
# スタートアップスクリプトを差しかえ
Copy-Item ..\startnet.cmd .\WinPE\mount\Windows\System32\
# 起動時に「Press any Key boot From CD or DVD...」を表示させないための設定
Copy-Item ..\efisys_noprompt.bin .\WinPE\fwfiles\efisys.bin -Force
# 日本語化
$PEOCs = Join-Path $env:WinPERoot "\$script:Architecture\WinPE_OCs"
dism /Image:.\WinPE\mount /Add-Package /Packagepath:"$PEOCs\WinPE-FontSupport-JA-JP.cab"
dism /Image:.\WinPE\mount /Add-Package /Packagepath:"$PEOCs\ja-jp\lp.cab"
dism /Image:.\WinPE\mount /Set-Allintl:ja-jp
dism /Image:.\WinPE\mount /Set-Inputlocale:0411:00000411
dism /Image:.\WinPE\mount /Set-Layereddriver:6
dism /Image:.\WinPE\mount /Set-Timezone:"Tokyo Standard Time"
# コミット
dism /unmount-image /mountdir:.\WinPE\mount /commit
}
catch {
dism /unmount-image /mountdir:.\WinPE\mount /discard
throw
}
# 不要な言語ファイル削除
Get-ChildItem .\WinPE\media -Directory -Filter '*-*' | ? { $_.Name -notin ('ja-jp', 'en-us') } | Remove-Item -Recurse
# ============================
# ISO 作成
# ============================
# MakeWinPEMediaが進行状況をエラーストリームに出力しているため、無視させる必要がある
$OriginalEA = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
MakeWinPEMedia /iso /f ".\WinPE" "..\$script:OutputFileName"
$ErrorActionPreference = $OriginalEA
Write-Host '-------- Completed --------' -ForegroundColor Green
wpeinit
wpeutil disablefirewall
powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment