scripts
This commit is contained in:
parent
0bae42c588
commit
8935f63123
35
postgres-odbc.ps1
Normal file
35
postgres-odbc.ps1
Normal file
@ -0,0 +1,35 @@
|
||||
# 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")
|
||||
|
14
sql_server/mssql_csv.ps1
Normal file
14
sql_server/mssql_csv.ps1
Normal file
@ -0,0 +1,14 @@
|
||||
# Check if the SqlServer module is installed
|
||||
if (-not (Get-Module -Name SqlServer -ListAvailable)) {
|
||||
# If not installed, install the SqlServer module
|
||||
Install-Module -Name SqlServer -Force
|
||||
}
|
||||
#import module
|
||||
Import-Module -Name SqlServer
|
||||
|
||||
# Define variables for SQL command and destination file path
|
||||
$SqlQuery = "SELECT top 1000 * FROM rlarp.osm_stack WHERE version = 'Actual'"
|
||||
$DestinationFilePath = "C:\Users\ptrowbridge\Downloads\osm_stack.csv"
|
||||
|
||||
# Execute the SQL query and export to CSV
|
||||
Invoke-Sqlcmd -ServerInstance "usmidsql01" -Database "fanalysis" -Query $SqlQuery -TrustServerCertificate | Export-Csv -Path $DestinationFilePath -NoTypeInformation
|
Loading…
Reference in New Issue
Block a user