64 lines
2.2 KiB
PowerShell
64 lines
2.2 KiB
PowerShell
# PowerShell Script to Execute SQL Server Setup
|
|
# Database: AccManager
|
|
# Server: 172.20.235.176
|
|
|
|
# SQL Server Connection Info
|
|
$ServerName = "172.20.235.176"
|
|
$Username = "sa"
|
|
$Password = "robotics@2020"
|
|
$SqlScriptPath = ".\setup.sql"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "AccManager Database Setup" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Check if sqlcmd is available
|
|
if (-not (Get-Command sqlcmd -ErrorAction SilentlyContinue)) {
|
|
Write-Host "ERROR: sqlcmd is not available on this system." -ForegroundColor Red
|
|
Write-Host "Please install SQL Server Command Line Tools (sqlcmd)" -ForegroundColor Yellow
|
|
Write-Host "Download from: https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility" -ForegroundColor Yellow
|
|
exit
|
|
}
|
|
|
|
# Check if SQL script file exists
|
|
if (-not (Test-Path $SqlScriptPath)) {
|
|
Write-Host "ERROR: SQL script file not found: $SqlScriptPath" -ForegroundColor Red
|
|
exit
|
|
}
|
|
|
|
Write-Host "Server: $ServerName" -ForegroundColor Green
|
|
Write-Host "User: $Username" -ForegroundColor Green
|
|
Write-Host "Script: $SqlScriptPath" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Execute SQL Script
|
|
Write-Host "Executing SQL script..." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
try {
|
|
sqlcmd -S $ServerName -U $Username -P $Password -i $SqlScriptPath -o "setup_output.log"
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "SETUP COMPLETED SUCCESSFULLY!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Output saved to: setup_output.log" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Display output
|
|
Write-Host "Setup Output:" -ForegroundColor Cyan
|
|
Get-Content "setup_output.log"
|
|
}
|
|
catch {
|
|
Write-Host "ERROR executing SQL script:" -ForegroundColor Red
|
|
Write-Host $_.Exception.Message -ForegroundColor Red
|
|
exit
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "Database is ready to use!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|