Skip to content

Instantly share code, notes, and snippets.

@watahani
Last active August 6, 2019 12:03
Show Gist options
  • Save watahani/c54377a3b84fe965b439583e845f9766 to your computer and use it in GitHub Desktop.
Save watahani/c54377a3b84fe965b439583e845f9766 to your computer and use it in GitHub Desktop.
# iex (New-Object System.Net.WebClient).downloadString("https://gist.githubusercontent.com/watahani/c54377a3b84fe965b439583e845f9766/raw/278e68045b487e0f85adb30740278074ba2a44fd/Setup-AzureVM.ps1")
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Set-ExecutionPolicy RemoteSigned
$runReg = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$runRegKeyName = "azureVMSetup"
function Disable-Services {
# Disable MapBroker
Get-Service -Name MapsBroker | Set-Service -StartupType Disabled
# Disable OneSyncSvc
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OneSyncSvc" /v Start /d 4 /t "REG_DWORD" /f
}
function Install-ToolsByScoop {
try {
[environment]::setEnvironmentVariable('SCOOP','C:\scoop','Machine')
$env:SCOOP = 'C:\scoop'
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop install sudo git
scoop bucket add extras
sudo scoop install -g git 7zip fiddler wireshark firefox chromium tor-browser win-acme
Install-PackageProvider NuGet -Force
Install-Module PSWindowsUpdate -Force
Install-Module -Name ACMESharp -Force
Get-PackageProvider Chocolatey -Force
Install-Package networkmonitor -Force
Install-Package winpcap -Force
Install-Package microsoft-message-analyzer -Force
}
catch {
Write-Host "error during additional apps install process"
}
}
# Thanks @akiyoshi-t https://qiita.com/akiyoshi-t/items/76eb446cc8f8ec360e00
function Install-Japanese-Language {
Write-Host "install japanese language..."
$LpTemp = "C:\LpTemp.cab"
$LpUrl = "http://download.windowsupdate.com/c/msdownload/update/software/updt/2016/09/lp_9a666295ebc1052c4c5ffbfa18368dfddebcd69a.cab"
$(New-Object System.Net.WebClient).downloadFile($LpUrl, $LpTemp)
Set-WinUserLanguageList -LanguageList ja-JP,en-US -Force
Write-Host "Start language installation as another task..."
$backgroundTask = Start-Process -PassThru -Filepath powershell.exe -ArgumentList "-c Add-WindowsPackage -PackagePath $LpTemp -Online"
# install tools while installation working....
Install-ToolsByScoop
if (-not $backgroundTask.HasExit) {
Wait-Process $backgroudTask.Id
}
Write-Host "Finish languagefile installation"
Write-Host "Set default inputMethod"
Set-WinDefaultInputMethodOverride -InputTip "0411:00000411"
Set-WinLanguageBarOption -UseLegacySwitchMode -UseLegacyLanguageBar
Remove-Item $LpTemp -Force
Write-Host ">>> waiting 3 sec..."
Start-Sleep -s 3
Write-Host "setup japanese timezone and language..."
Set-WinUILanguageOverride -Language ja-JP
Set-WinCultureFromLanguageListOptOut -OptOut $False
Set-WinHomeLocation -GeoId 0x7A
Set-WinSystemLocale -SystemLocale ja-JP
Set-TimeZone -Id "Tokyo Standard Time"
}
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "#############################################"
Write-Host " Azure VM Setup Script v0.2"
Write-Host "#############################################"
Write-Host ""
Write-Host ""
Write-Host ""
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy RemoteSigned
$scriptUrl = "https://gist.githubusercontent.com/watahani/c54377a3b84fe965b439583e845f9766/raw/278e68045b487e0f85adb30740278074ba2a44fd/Setup-AzureVM.ps1"
$tmpScriptPath = "C:\tmp.ps1"
$stepfile = "c:\setup_step.txt"
if(-not (Test-Path $stepfile)) {
$(New-Object System.Net.WebClient).downloadFile($scriptUrl, $tmpScriptPath)
New-Item $stepfile -Value 1
}
$step = Get-Content -Path $stepfile
Write-Host ">>> step $step"
Write-Host ""
switch ($step) {
1 {
Set-Content -Path $stepfile -Value ($step + 1)
Disable-Services
Install-Japanese-Language
Set-ItemProperty $runReg -Name $runRegKeyName -Value "powershell.exe -ExecutionPolicy Bypass `"$tmpScriptPath`""
}
2 {
Set-Content -Path $stepfile -Value ($step + 1)
Install-WindowsUpdate -AutoReboot -AcceptAll
}
default {
Write-Host ">>> delete auto run script..."
try {
Get-ItemProperty -Path $runReg | Select-Object -ExpandProperty $runRegKeyName -ErrorAction Stop | Out-Null
Remove-ItemProperty -Path $runReg -Name $runRegKeyName
Write-Host "auto run script has deleted"
}
catch {
Write-Host "not found auto run script..."
}
Write-Host "completed!"
Read-Host "press any key..."
Exit 0
}
}
Restart-Computer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment