PS: Script to update SQL DB

Below is a PowerShell scripted version of silently updating the SQL DB and saving the SQL query results in a log file.

 

$sql_file = ‘C:appUpdate-SQLDB.sql’
$sql_log  = ‘C:appUpdate-SQLDB.log’

Add-Content -Path $sql_file  "Update <DBName>..<TableName> set db_database_name = ‘CustomDB_00’ Where db_database_name = ‘AppDefaultDB’" ;
Add-Content -Path $sql_file  "Update <DBName>..<TableName> set db_database_name = ‘CustomDB_Trial_00’ Where db_database_name = ‘AppDefaultDB_Trial’"

Write-Output "$sql_file" >> "$sql_log"

SQLCMD.EXE -U sa -P ‘sapassword’ -S <DBServerName><DBInstanceName> -i $sql_file | out-File $sql_log

Leave a Reply

Your email address will not be published. Required fields are marked *