毎度毎度 EC2 の Windows Server の初期設定が手間なので、自動化する方法を模索していました。
インスタンス作成時のユーザーデータで PowerShell スクリプトを実行できようですね。
パスワード Z1(5zORN は変更して使ってください。
参考: https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html
参考: https://stackoverflow.com/questions/9368305/disable-ie-security-on-windows-server-via-powershell
参考: https://forum.pulseway.com/topic/1940-install-firefox-with-powershell/
<powershell>
function Disable-InternetExplorerESC {
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0
Stop-Process -Name Explorer
Write-Host "IE Enhanced Security Configuration (ESC) has been disabled." -ForegroundColor Green
}
Disable-InternetExplorerESC
net user Administrator "Z1(5zORN"
function Install-FireFox {
# Silent Install Firefox
# Download URL: https://www.mozilla.org/en-US/firefox/all/
# Path for the workdir
$workdir = "c:\installer\"
# Check if work directory exists if not create it
If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir -ItemType directory }
# Download the installer
$source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=ja"
$destination = "$workdir\firefox.exe"
# Check if Invoke-Webrequest exists otherwise execute WebClient
if (Get-Command 'Invoke-Webrequest')
{
Invoke-WebRequest $source -OutFile $destination
}
else
{
$WebClient = New-Object System.Net.WebClient
$webclient.DownloadFile($source, $destination)
}
# Start the installation
Start-Process -FilePath "$workdir\firefox.exe" -ArgumentList "/S"
# Wait XX Seconds for the installation to finish
Start-Sleep -s 35
# Remove the installer
rm -Force $workdir\firefox*
}
Install-FireFox
function Install-Choco {
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
Install-Choco
# PowerShell Remoting を有効化
Enable-PSRemoting -SkipNetworkProfileCheck
# 任意ホストからの接続を許可
Set-Item WSMan:\localhost\Client\TrustedHosts -Value * -Force
</powershell>