forked from brianfgonzalez/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallSQL.ps1
More file actions
47 lines (43 loc) · 1.95 KB
/
InstallSQL.ps1
File metadata and controls
47 lines (43 loc) · 1.95 KB
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
38
39
40
41
42
43
44
45
46
47
#=================Variables========================
#Grab Current Directory
$oInvocation = (Get-Variable MyInvocation).Value
$sCurrentDirectory = Split-Path $oInvocation.MyCommand.Path
$sLogLocation = "C:\Windows\Temp\SQLInstallation.log"
If (Test-Path $sLogLocation) { Remove-Item $sLogLocation -Force }
#=================Functions========================
Function WaitForFile($sFileName)
{
#Loop Script with included sleep and file check
For($i=1; $i -le 45; $i++)
{
If (Test-Path $sFileName){break}
Start-Sleep -Seconds 60 #Checks for existance of file every minute.
}
}
Function WriteToLog($sMessage)
{
$sDate = Get-Date -Format "MM/dd/yyyy"
$sTime = Get-Date -Format "hh:mm:ss"
$tMessage = "$sDate $sTime : $sMessage"
$tMessage | Out-File -FilePath $sLogLocation -Append
}
#=================Main Routine========================
WriteToLog "Install SQL 2008 R2 script has begun"
If (!(Test-Path "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBLog.ldf"))
{
#Copy Install Files to C:\Windows\Temp
If (!(Test-Path "C:\Windows\Temp\SQL08R2\x64\setup\sql_common_core_msi\pfiles32\sqlservr\100\com\kdz5mbsd.dll"))
{
WriteToLog "Copy of SQL install files is nessesary and is beginning."
Copy-Item "$sCurrentDirectory\*" "C:\Windows\Temp\SQL08R2\" -Recurse -Force
WriteToLog "Copy of SQL install files is complete."
}
#Start Installation
WriteToLog "SQL Installation is starting..."
Start-Process -FilePath "C:\Windows\Temp\SQL08R2\setup.exe" -ArgumentList "/Q /IACCEPTSQLSERVERLICENSETERMS /SAPWD=P@ssw0rd /ConfigurationFile=C:\Windows\Temp\SQL08R2\ConfigurationFile.ini" -Wait -WindowStyle Maximized
WriteToLog "Install returned to Command Shell with the following code: $LASTEXITCODE"
WaitForFile "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBLog.ldf"
WriteToLog "Install is complete and verified."
} else {
WriteToLog "SQL 2008 R2 is already installed."
}