Skip to content

Instantly share code, notes, and snippets.

@stknohg
Created March 14, 2023 05:14
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 stknohg/4a6774208cbf9e2db6959191fcc4ac15 to your computer and use it in GitHub Desktop.
Save stknohg/4a6774208cbf9e2db6959191fcc4ac15 to your computer and use it in GitHub Desktop.
Windows環境にPostgreSQLのコマンドラインツールをインストールするスクリプト
# Download Installer
$ProgressPreference = 'SilentlyContinue'
$installerUrl = 'https://get.enterprisedb.com/postgresql/postgresql-15.2-1-windows-x64.exe'
$installerLocalPath = Join-Path $env:TEMP 'postgresql-windows-x64.exe'
Invoke-WebRequest -Uri $installerUrl -OutFile $installerLocalPath
# Invoke Installer
$params = @{
FilePath = $installerLocalPath # InstallBuilder
ArgumentList = @('--mode unattended', '--unattendedmodeui none', '--disable-components server,pgAdmin,stackbuilder')
Wait = $true
PassThru = $true
}
$proc = Start-Process @params
switch ($proc.ExitCode) {
0 {
# インストール成功
break
}
Default {
# その他のエラー
Write-Error ("Failed to install.(Exit code={0})" -f $_)
break
}
}
# Remove Installer
if (Test-Path -LiteralPath $installerLocalPath) {
Remove-Item -LiteralPath $installerLocalPath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment