-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_database.ps1
32 lines (28 loc) · 1017 Bytes
/
create_database.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
function create_sql_database
{
param (
[String] $inst,
[String] $username,
[String] $password,
[String] $dbName
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
try {
$sqlServer = New-Object ('Microsoft.SqlServer.Management.SMO.Server') $inst
#if($username -eq "" -and $password -eq "") {
# $sqlServer.ConnectionContext.LoginSecure = $true
#} else {
# $sqlServer.ConnectionContext.LoginSecure = $false
# $sqlServer.ConnectionContext.set_Login($username)
# $sqlServer.ConnectionContext.set_Password($password)
#}
if($sqlServer.Databases[$dbName] -eq $null) {
$db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($sqlServer, $dbName)
$db.Create()
} else {
Write-Host "Database already exists!"
}
} catch [Exception] {
$error[0] | format-list -force
}
}