You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell安装Oracle、PostgreSQL及检测Windows系统安装状态求助

Hey there! Let's tackle your PowerShell database needs step by step—since you're new to PowerShell, I'll keep things straightforward and actionable 😊

1. Detecting Installed Databases on Windows

First, let's cover how to check if SQL Server, Oracle, and PostgreSQL are already installed on your Windows machine.

1.1 SQL Server Detection

There are a couple reliable ways to check for SQL Server:

  • Registry Check: This is fast and targets SQL Server's instance registry entries
    # List all installed SQL Server instances
    Get-ItemProperty "HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL" -ErrorAction SilentlyContinue | 
        Select-Object -ExpandProperty "(default)"
    
  • Installed Programs List: If you want more details like version, use this (note: Win32_Product can be slow as it validates MSI packages)
    Get-CimInstance -ClassName Win32_Product | 
        Where-Object {$_.Name -like "*SQL Server*"} | 
        Select-Object Name, Version, InstallLocation
    

1.2 Oracle Detection (Your Working Command, Formalized)

Since you already have this working, here's a polished version for reference that pulls key details:

# Check Oracle installations and their home directories
Get-ChildItem "HKLM:\Software\Oracle\KEY*" -ErrorAction SilentlyContinue | ForEach-Object {
    Get-ItemProperty $_.PSPath | 
        Select-Object @{Name="Oracle Home"; Expression={$_.Oracle_Home}}, Version
}

1.3 PostgreSQL Detection (The Fix You Need)

The reason your Oracle command fails for PostgreSQL is that PostgreSQL stores installation data in different registry paths. Try these methods:

  • Registry Check (Covers 64-bit and 32-bit):
    # Check both 64-bit and 32-bit registry paths for PostgreSQL
    $pgRegistryPaths = @("HKLM:\Software\PostgreSQL", "HKLM:\Software\Wow6432Node\PostgreSQL")
    
    foreach ($path in $pgRegistryPaths) {
        if (Test-Path $path) {
            Get-ChildItem $path | ForEach-Object {
                Get-ItemProperty $_.PSPath | 
                    Select-Object @{Name="Version"; Expression={$_.PSChildName}}, BaseDirectory, ServiceName
            }
        }
    }
    
  • Service Check: PostgreSQL runs a named service (usually postgresql-x64-XX where XX is the version)
    # List running or stopped PostgreSQL services
    Get-Service -Name "postgresql*" -ErrorAction SilentlyContinue | 
        Select-Object Name, Status, DisplayName
    
  • Installed Programs List:
    Get-CimInstance -ClassName Win32_Product | 
        Where-Object {$_.Name -like "*PostgreSQL*"} | 
        Select-Object Name, Version, InstallLocation
    
2. Installing Oracle and PostgreSQL via PowerShell

Now let's walk through silent installations for both databases—this is the most efficient way to install via PowerShell.

2.1 Oracle Installation

Oracle requires a response file for silent installs (to avoid interactive prompts):

  1. Download the Oracle installation media (zip files) and extract to a folder (e.g., C:\OracleInstall)
  2. Generate a response file by running setup.exe -generateResponseFile and configure it with your settings (edition, install path, passwords, etc.)
  3. Run the silent install with PowerShell:
    # Silent Oracle install using response file
    Start-Process -FilePath "C:\OracleInstall\setup.exe" -ArgumentList "-silent -responseFile C:\OracleInstall\your-response-file.rsp" -Wait -NoNewWindow
    

2.2 PostgreSQL Installation

PostgreSQL's installer supports direct command-line arguments for silent installs:

  1. Download the PostgreSQL installer (e.g., postgresql-16.2-1-windows-x64.exe)
  2. Run this PowerShell command (adjust paths and settings to your needs):
    # Silent PostgreSQL install example
    Start-Process -FilePath "C:\Downloads\postgresql-16.2-1-windows-x64.exe" -ArgumentList `
        "--mode unattended", `
        "--superpassword YourStrongPassword123", `
        "--install_dir C:\Program Files\PostgreSQL\16", `
        "--serverport 5432", `
        "--enable-components server,pgAdmin4" `
    -Wait -NoNewWindow
    
    Key arguments explained:
    • --mode unattended: Runs the install without prompts
    • --superpassword: Sets the password for the default postgres admin user
    • --install_dir: Defines where PostgreSQL will be installed
    • --enable-components: Choose which parts to install (server, pgAdmin, etc.)

内容的提问来源于stack exchange,提问作者Prajwal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:20:34