-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.ps1
37 lines (26 loc) · 1.01 KB
/
start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# The script sets the sa password and start the SQL Service
# Also it attaches additional database from the disk
# The format for attach_dbs
param(
[Parameter(Mandatory=$false)]
[string]$sa_password
)
# start the service
Write-Verbose "Starting SQL Server"
start-service MSSQL`$SQLEXPRESS
Write-Verbose "Setting max RAM of 800MB"
sqlcmd -S 127.0.0.1 -Q "USE master; EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'max server memory (MB)', 800; RECONFIGURE WITH OVERRIDE;EXEC sp_configure 'show advanced options', 0;"
if($sa_password -ne "_")
{
Write-Verbose "Changing SA login credentials"
$sqlcmd = "ALTER LOGIN sa with password='$sa_password';ALTER LOGIN sa ENABLE;"
& sqlcmd -S 127.0.0.1 -Q $sqlcmd
}
Write-Verbose "Started SQL Server."
$lastCheck = (Get-Date).AddSeconds(-2)
while ($true)
{
Get-EventLog -LogName Application -Source "MSSQL*" -After $lastCheck | Select-Object TimeGenerated, EntryType, Message
$lastCheck = Get-Date
Start-Sleep -Seconds 2
}