-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateSymbolsInPS.ps1
148 lines (123 loc) · 5.97 KB
/
GenerateSymbolsInPS.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function GenerateSymbolsLookupDatabaseInSQL
{
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing");
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo");
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement");
function GenerateSymbolsForDatabase
{
[CmdletBinding()]param ([String]$Server, [String]$Database)
$ClientNAVDir = 'C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client'
$Command = """$ClientNAVDir\finsql.exe"" command=generatesymbolreference,servername=$Server,database=$Database"
Write-host $Command
cmd /c $Command
}
function Get-SQLServerList()
{
$comboBox2.Items.Clear();
$computer = "$env:COMPUTERNAME"
$MC = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer($computer);
foreach($instance in ($MC.Services | Where-Object {$_.Type -eq "SqlServer"}))
{
if (($instance.DisplayName -eq 'MSSQLSERVER') -or ($instance.DisplayName -eq 'SQL Server (MSSQLSERVER)'))
{$comboBox2.Items.Add($computer)}
elseif ($instance.DisplayName.Contains('SQL Server ('))
{[int]$lenght = $instance.DisplayName.Length - 13
$comboBox2.Items.Add(-join ($computer,'\',($instance.DisplayName.SubString(12,$lenght))))}
}
$com
}
function Get-DBList($server)
{
$comboBox1.Items.Clear();
$script:DatabaseName = @{}
$srv = New-Object 'Microsoft.SqlServer.Management.Smo.Server' $server
[int]$i = 0
foreach($sqlDatabase in $srv.Databases)
{
$i++
$DatabaseName.Add($i,$sqlDatabase)
}
foreach($databaseID in $databasename.keys)
{
$DBname = $databasename[$databaseID]
$DBname2 = $DBname.ToString()
$DBname2 = $DBname2.trimstart('[')
$DBname2 = $DBname2.trimend(']')
$IsSystemDatabase = ($DBname2 -like 'master') -or ($DBname2 -like 'tempdb') -or ($DBname2 -like 'model') -or ($DBname2 -like 'msdb') -or ($DBname2.startswith('ReportServer'))
if (-not $IsSystemDatabase)
{$comboBox1.Items.add($DBname2)}
}
}
#Create the Main Window
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Generate Dynamics BC Symbols"
$objForm.Size = New-Object System.Drawing.Size(300,300)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$script:x1=$comboBox2.Text;$script:x2=$comboBox1.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
#Create the Buttons
$GetSQLButton = New-Object System.Windows.Forms.Button
$GetSQLButton.Location = New-Object System.Drawing.Size(10,125)
$GetSQLButton.Size = New-Object System.Drawing.Size(260,23)
$GetSQLButton.Text = "Load List Of Servers"
$GetSQLButton.Add_Click({Get-SQLServerList})
$objForm.Controls.Add($GetSQLButton)
$GetDBButton = New-Object System.Windows.Forms.Button
$GetDBButton.Location = New-Object System.Drawing.Size(10,155)
$GetDBButton.Size = New-Object System.Drawing.Size(260,23)
$GetDBButton.Text = "Load List Of Databases"
$GetDBButton.Add_Click({
$script:x1=$comboBox2.Text
if ($script:x1 -ne '')
{Get-DBlist($script:x1)}
else
{[System.Windows.Forms.MessageBox]::Show("Please enter <servername>\<instance> in the server field.")}
})
$objForm.Controls.Add($GetDBButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(15,220)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(190,220)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$script:x1=$ComboBox2.Text;$script:x2=$ComboBox1.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
#Create Labels and ComboBox
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Server"
$objForm.Controls.Add($objLabel)
$script:comboBox2 = New-Object System.Windows.Forms.ComboBox
$comboBox2.Location = New-Object System.Drawing.Size(10,40)
$comboBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($comboBox2)
$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,65)
$objLabel2.Size = New-Object System.Drawing.Size(280,20)
$objLabel2.Text = "Database"
$objForm.Controls.Add($objLabel2)
$script:comboBox1 = New-Object System.Windows.Forms.ComboBox
$comboBox1.Location = New-Object System.Drawing.Size(10,85)
$comboBox1.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($comboBox1)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
if (($x1 -ne '') -and ($x2 -ne ''))
{GenerateSymbolsForDatabase -Server $x1 -Database $x2}
else
{
[System.Windows.Forms.MessageBox]::Show("Please enter server and database")
Write-Error 'Please enter server and database'
}
}
GenerateSymbolsLookupDatabaseInSQL