-
Notifications
You must be signed in to change notification settings - Fork 3
/
DbDeploy.psm1
45 lines (39 loc) · 1.01 KB
/
DbDeploy.psm1
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
function Use-PPSnapin($name)
{
$loaded = Get-PSSnapin -Name $name -ErrorAction SilentlyContinue
if (!$loaded)
{
Add-PSSnapin $name
}
}
function Invoke-SqlFile([string]$server,[string]$file)
{
$outfile = [System.IO.Path]::GetTempFileName()
& sqlcmd.exe -S $server -E -x -b -i $file -o $outfile
$success = $?
$resultText = [IO.File]::ReadAllText($outfile)
Remove-Item $outfile
return @{Success = $success;ResultText=$resultText}
}
function Get-SQLProviderPath([string]$server,[string]$database)
{
($serverMachine,$instanceName) = $server.Split("\")
$pathServerMachine = switch($serverMachine)
{
. { (hostname) }
"(local)" { (hostname) }
local { (hostname) }
localhost { (hostname) }
default { $serverMachine }
}
if (!$instanceName)
{
$instanceName = "Default"
}
if (!$pathServerMachine)
{
Write-Error "dsf $pathServerMachine"
}
return "SQLSERVER:\SQL\$pathServerMachine\$instanceName\Databases\$database"
}
export-modulemember -function Use-PPSnapin,Get-SQLProviderPath,Invoke*