-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLInvokeEnc.ps1
More file actions
80 lines (78 loc) · 2.06 KB
/
SQLInvokeEnc.ps1
File metadata and controls
80 lines (78 loc) · 2.06 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
################################################################################################################
####
##
## ORIGINAL PS SCRIPT FROM: MichaelMihalik
##
####
Param(
[string]$HomeDirString,
[string]$ServerName,
[string]$DatabaseName
)
############globals############
$ErrorActionPreference = "continue"
$script:Exclusions = @("tests", "triggers","setup")
############FUNCTIONS############
function IterateDirectories($directory)
{
$iHomeDir = Get-ChildItem $directory
#
foreach($iFile in $iHomeDir)
{
Write-Host "Executing Procedure: " $iFile
InvokeCmd $iFile.FullName
}
}
function InvokeCmd($inputFilePath)
{
#Write-Host $inputFilePath
Invoke-Sqlcmd -InputFile $inputFilePath -ServerInstance $ServerName -Database $DatabaseName
}
############MAIN############
##Validate##
if([string]::IsNullOrEmpty($HomeDirString)){
$HomeDirString = "C:\asci\ActiveBatch\V10\Release\JobScheduler\Database\SqlServer"
}
if([string]::IsNullOrEmpty($ServerName)){
$ServerName = "PRD3002SUPSQL"
}
if([string]::IsNullOrEmpty($DatabaseName)){
$DatabaseName = "ASCICAS-00061299"
}
#Set HomeDir
Write-Host -ForegroundColor Yellow "Home Directory: " $HomeDirString
$HomeDir = Get-ChildItem $HomeDirString
#push
Push-Location
##Loop##
foreach($obj in $HomeDir)
{
#If an exclusion list item is found -- skip it
if($Exclusions.Contains($obj.Name))
{
continue
}
#Otherwise - detect this is a dir/file
if($obj -is [System.IO.DirectoryInfo])
{
IterateDirectories $obj.FullName
}
elseif ($obj -is [System.IO.FileInfo])
{
Write-Host "Executing Procedure: " $obj
InvokeCmd $obj.FullName
}
}
#Add Triggers Later as to not overwrite them.
if($HomeDir.Length -eq 0){
return
}
$triggersPath = $HomeDir.DirectoryName.Item(0) + "\triggers";
$triggersDir = Get-ChildItem $triggersPath
foreach($obj in $triggersDir)
{
Write-Host "Executing Procedure: " $obj
InvokeCmd $obj.FullName
}
#Pop
Pop-Location