-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathTextClassificationSetup.ps1
358 lines (278 loc) · 11.3 KB
/
TextClassificationSetup.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
[CmdletBinding()]
param(
[parameter(Mandatory=$false, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$serverName,
[parameter(Mandatory=$false, Position=2)]
[ValidateNotNullOrEmpty()]
[string]$username,
[parameter(Mandatory=$false, Position=3)]
[ValidateNotNullOrEmpty()]
[string]$password,
[parameter(Mandatory=$false, Position=4)]
[ValidateNotNullOrEmpty()]
[string]$Prompt
)
###Check to see if user is Admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")
if ($isAdmin -eq 'True')
{
# {
# ##Check to see is Advanced Analytics is installed
# $Query =
# "SELECT CASE WHEN SERVERPROPERTY('IsAdvancedAnalyticsInstalled') = 1 THEN 'Yes' ELSE 'No' END"
# $IsAdv = Invoke-Sqlcmd -Query $Query
# $IsAdv = $IsAdv.Item(0)
# if($IsAdv -eq 'No')
# {
# Write-Host
# ("To run this solution , Please install SQLAdvanced Analytics")
# Start-Sleep -s 20
# }
# ELSE
# {
# Write-Host ("Advanced Analytics is present, set up can continue")
$startTime = Get-Date
$setupLog = "c:\tmp\text_setup_log.txt"
Start-Transcript -Path $setupLog -Append
$startTime = Get-Date
Write-Host
("Start time:$startTime")
#$Prompt= if ($Prompt -match '^y(es)?$') {'Y'} else {'N'}
$Prompt = 'N'
##Change Values here for Different Solutions
$SolutionName = "TextClassification"
$SolutionFullName = "ml-server-text-classification"
$Shortcut = "SolutionHelp.url"
### DON'T FORGET TO CHANGE TO MASTER LATER...
$Branch = "master"
$InstallR = 'Yes' ## If Solution has a R Version this should be 'Yes' Else 'No'
$InstallPy = 'Yes' ## If Solution has a Py Version this should be 'Yes' Else 'No'
$SampleWeb = 'No' ## If Solution has a Sample Website this should be 'Yes' Else 'No'
$EnableFileStream = 'No' ## If Solution Requires FileStream DB this should be 'Yes' Else 'No'
$UsePowerBI = 'No' ## If Solution uses PowerBI
$Prompt = 'N'
$MixedAuth = 'No'
$InstallPowerShellUpdate = 'No'
###These probably don't need to change , but make sure files are placed in the correct directory structure
$solutionTemplateName = "Solutions"
$solutionTemplatePath = "C:\" + $solutionTemplateName
$checkoutDir = $SolutionName
$SolutionPath = $solutionTemplatePath + '\' + $checkoutDir
$desktop = "C:\Users\Public\Desktop\"
$scriptPath = $SolutionPath + "\Resources\ActionScripts\"
$SolutionData = $SolutionPath + "\Data\"
###If not run as DSVM , prompt for UI and PW
if ($SampleWeb -eq "Yes")
{
if([string]::IsNullOrEmpty($username))
{
$Credential = $Host.ui.PromptForCredential("Need credentials", "Please supply an user name and password to configure SQL for mixed mode authentication.", "", "")
$username = $credential.Username
$password = $credential.GetNetworkCredential().password
}
}
##########################################################################
#Clone Data from GIT
##########################################################################
$clone = "git clone --branch $Branch --single-branch https://github.com/Microsoft/$SolutionFullName $solutionPath"
if (Test-Path $SolutionPath)
{
(Write-Host "Solution has already been cloned")
}
else
{
Invoke-Expression $clone
}
If ($InstalR -eq 'Yes')
{
Write-Host
("Installing R Packages")
Set-Location "C:\Solutions\$SolutionName\Resources\ActionScripts\"
# install R Packages
Rscript install.R
}
##Check DSVM Version
Set-Location $scriptPath
invoke-expression .\CheckDSVMVersion.bat
#################################################################
##DSVM Does not have SQLServer Powershell Module Install or Update
#################################################################
if ($InstallPowerShellUpdate -eq 'Yes')
{
if (Get-Module -ListAvailable -Name SQLServer)
{
Write-Host
("Updating SQLServer Power Shell Module")
Update-Module -Name "SQLServer" -MaximumVersion 21.0.17199
Import-Module -Name SqlServer -MaximumVersion 21.0.17199 -Force
}
Else
{
Write-Host
("Installing SQLServer Power Shell Module")
Install-Module -Name SqlServer -RequiredVersion 21.0.17199 -Scope AllUsers -AllowClobber -Force}
Import-Module -Name SqlServer -MaximumVersion 21.0.17199 -Force
}
## if FileStreamDB is Required Alter Firewall ports for 139 and 445
if ($EnableFileStream -eq 'Yes')
{
netsh advfirewall firewall add rule name="Open Port 139" dir=in action=allow protocol=TCP localport=139
netsh advfirewall firewall add rule name="Open Port 445" dir=in action=allow protocol=TCP localport=445
Write-Host
("Firewall has been opened for filestream access")
}
############################################################################################
#Configure SQL to Run our Solutions
############################################################################################
$Query = "SELECT SERVERPROPERTY('ServerName')"
$si = invoke-sqlcmd -Query $Query
$si = $si.Item(0)
$serverName = if([string]::IsNullOrEmpty($servername)) {$si} Else {$ServerName}
Write-Host
("Servername set to $serverName")
### Change Authentication From Windows Auth to Mixed Mode
If ($MixedAuth -eq 'Yes')
{
Write-Host
("Changing SQL Authentication to Mixed Mode")
Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2;" -ServerInstance "LocalHost"
$Query = "CREATE LOGIN $username WITH PASSWORD=N'$password', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
$Query = "ALTER SERVER ROLE [sysadmin] ADD MEMBER $username"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
}
### Allow Running of External Scripts , this is to allow R Services to Connect to SQL
Write-Host
("Configuring SQL to allow running of External Scripts")
Invoke-Sqlcmd -Query "EXEC sp_configure 'external scripts enabled', 1"
### Force Change in SQL Policy on External Scripts
Invoke-Sqlcmd -Query "RECONFIGURE WITH OVERRIDE"
Write-Host
("SQL Server Configured to allow running of External Scripts")
### Enable FileStreamDB if Required by Solution
if ($EnableFileStream -eq 'Yes')
{
$instance = "MSSQLSERVER"
$wmi = Get-WmiObject -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement14" -Class FilestreamSettings | where-object {$_.InstanceName -eq $instance}
$wmi.EnableFilestream(3, $instance)
Restart-Service -Name "MSSQ*" -Force
#Import-Module "sqlps" -DisableNameChecking
Invoke-Sqlcmd "EXEC sp_configure filestream_access_level, 2"
Invoke-Sqlcmd "RECONFIGURE WITH OVERRIDE"
Stop-Service "MSSQ*"
Start-Service "MSSQ*"
}
ELSE
{
Write-Host
("Restarting SQL Services")
### Changes Above Require Services to be cycled to take effect
### Stop the SQL Service and Launchpad wild cards are used to account for named instances
Restart-Service -Name "MSSQ*" -Force
}
###Install SQL CU
Write-Host
("Checking SQL CU Version If Behind install Latest CU")
$Query = "SELECT CASE
WHEN
(RIGHT(CAST(SERVERPROPERTY('ProductUpdateLevel') as varchar),1) >= 1)
AND
(SELECT Left(CAST(SERVERPROPERTY('productversion') as varchar),2))>= 14
THEN 1
ELSE 0
END "
$RequireCuUpdate = Invoke-Sqlcmd -Query $Query
$RequireCuUpdate = $RequireCuUpdate.Item(0)
##$RequireCuUpdate = "1"
IF ($RequireCuUpdate -eq 0)
{
WRITE-Host
("Downloading Latest CU")
##cu1
## Start-BitsTransfer -Source "http://download.windowsupdate.com/d/msdownload/update/software/updt/2017/12/sqlserver2017-kb4038634-x64_a75ab79103d72ce094866404607c2e84ae777d43.exe" -Destination c:\tmp\sqlserver2017CU1.exe
##cu3
## Start-BitsTransfer -Source "http://download.windowsupdate.com/d/msdownload/update/software/updt/2018/01/sqlserver2017-kb4052987-x64_a533b82e49cb9a5eea52cd2339db18aa4017587b.exe" -Destination c:\tmp\sqlserver2017CU3.exe
##CU4
Start-BitsTransfer -Source "http://download.windowsupdate.com/c/msdownload/update/software/updt/2018/03/sqlserver2017-kb4056498-x64_d1f84e3cfbda5006301c8e569a66a982777a8a75.exe" -Destination c:\tmp\sqlserver2017CU4.exe
$CU = "sqlserver2017CU4.exe"
Write-Host
("CU has been Downloaded now to install , go have a cocktail as this takes a while")
Invoke-Expression "c:\tmp\$CU /q /IAcceptSQLServerLicenseTerms /IACCEPTPYTHONLICENSETERMS /IACCEPTROPENLICENSETERMS /Action=Patch /InstanceName=MSSQLSERVER /FEATURES=SQLEngine,ADVANCEDANALYTICS,SQL_INST_MR,SQL_INST_MPY"
Write-Host
("CU Install has commenced")
Write-Host
("Powershell time to take a nap")
Start-Sleep -s 1000
Write-Host
("Powershell nap time is over")
###Unbind Python
Set-Location $scriptPath
invoke-expression ".\UpdateMLServer.bat"
Write-Host "ML Server has been updated"
}
ELSE
{
Write-Host
("CU is Current")
}
####Run Configure SQL to Create Databases and Populate with needed Data
$ConfigureSql = "C:\Solutions\$SolutionName\Resources\ActionScripts\ConfigureSQL.ps1 $ServerName $SolutionName $InstallPy $InstallR $EnableFileStream"
Invoke-Expression $ConfigureSQL
Write-Host
("Done with configuration changes to SQL Server")
If ($UsePowerBI -eq 'Yes')
{
Write-Host
("This Solutions employees Power BI reports, so we need to install the latest version of Power BI")
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1
if (!$?)
{
Write-Host -ForeGroundColor Red
("Error installing Power BI Desktop. Please install latest Power BI manually.")
}
}
##Create Shortcuts and Autostart Help File
Copy-Item "$ScriptPath\$Shortcut" C:\Users\Public\Desktop\
Copy-Item "$ScriptPath\$Shortcut" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
Write-Host
("Help Files Copied to Desktop")
$WsShell = New-Object -ComObject WScript.Shell
$shortcut = $WsShell.CreateShortcut($desktop + $checkoutDir + ".lnk")
$shortcut.TargetPath = $solutionPath
$shortcut.Save()
# install modules for sample website
if($SampleWeb -eq "Yes")
{
Set-Location $SolutionPath\Website\
.\npm install
(Get-Content $SolutionPath\Website\server.js).replace('XXYOURSQLPW', $password) | Set-Content $SolutionPath\Website\server.js
(Get-Content $SolutionPath\Website\server.js).replace('XXYOURSQLUSER', $username) | Set-Content $SolutionPath\Website\server.js
}
##Launch HelpURL
Start-Process "https://microsoft.github.io/$SolutionFullName/"
$endTime = Get-Date
Write-Host
("$SolutionFullName Workflow Finished Successfully!")
$Duration = New-TimeSpan -Start $StartTime -End $EndTime
Write-Host
("Total Deployment Time = $Duration")
Stop-Transcript
## Close Powershell if not run on
if ($baseurl)
{Exit-PSHostProcess
EXIT}
}
#} uncomment this brace if we look for advanced anaytics
ELSE
{
Write-Host
("To install this Solution you need to run Powershell as an Administrator. This program will close automatically in 20 seconds")
Start-Sleep -s 20
Exit-PSHostProcess
EXIT
}