Created
July 28, 2015 15:53
-
-
Save Kevin-Bronsdijk/6dd705711e618b874ea2 to your computer and use it in GitHub Desktop.
scripting-sql-server-install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prerequisites | |
# Not required for Windows Server 2012 | |
# Custom pre-installation scripts | |
# Create Directories before running setup! | |
MD "X:\Program Files\Microsoft SQL Server" | |
MD "X:\Program Files (x86)\Microsoft SQL Server" | |
# Setup | |
Y:\setup.exe /configurationfile="X:\SQLConfigurationFile.ini" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module SQLPS -DisableNameChecking | |
#replace this with your instance name | |
$instanceName = "server\instance"; | |
if ((Get-ChildItem $env:temp -Filter *.log | | |
Select-String -pattern ("^*Setup closed with exit code: 0x00000000*") -AllMatches).Count -ne 2) | |
{ | |
Write-Output "Couldn't find exit code: 0x0000000" | |
} | |
else | |
{ | |
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName; | |
Try | |
{ | |
$dbName = "TestDB" | |
$db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($server, $dbName) | |
$db.Create() | |
Start-Sleep -s 15 | |
$server.KillDatabase($dbName) | |
Write-Host 'No errors found' | |
} | |
Catch | |
{ | |
$err = $_.Exception | |
while ( $err.InnerException ) | |
{ | |
$err = $err.InnerException; | |
}; | |
$exception = $err.Message; | |
Write-Host $exception; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment