1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] Amazon EC2 で ユーザーデータ を用いた Windows Server の初期設定

1
Last updated at Posted at 2019-12-12

毎度毎度 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>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?