# Check if the script is running as administrator $isAdmin = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544" if (-not $isAdmin) { # Re-launch the script with elevated privileges Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs exit } # note elevation Write-Host "Running with administrator privileges" # setup sources and destinations $zipUrl = "https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_15_00_0000.zip" $outputPath = Join-Path $env:USERPROFILE "Downloads\psqlodbc.zip" $extractPath = Join-Path $env:USERPROFILE "Downloads\psqlodbc" # Download the ZIP file Invoke-WebRequest -Uri $zipUrl -OutFile $outputPath # Extract the contents Expand-Archive -Path $outputPath -DestinationPath $extractPath -Force # Find and run the MSI file $msiFile = Get-ChildItem -Path $extractPath -Filter "psqlodbc-setup*" | Where-Object { ! $_.PSIsContainer } if ($msiFile) { Start-Process -FilePath $msiFile.FullName -Wait } # Remove downloaded files and extracted contents Remove-Item $outputPath -Force Remove-Item $extractPath -Recurse -Force # setup odbc dsn Add-OdbcDsn -Name "usmidsap02" -DriverName "PostgreSQL Unicode(x64)" -DsnType "System" -SetPropertyValue @("Server=usmidsap02", "Database=ubm", "UserName=report","Password=report")