Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevin-Bronsdijk/6dd705711e618b874ea2 to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/6dd705711e618b874ea2 to your computer and use it in GitHub Desktop.
scripting-sql-server-install
# 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"
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