-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinitializeTenerife.ps1
272 lines (247 loc) · 23.5 KB
/
initializeTenerife.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
#usage initialize.ps1
param
(
[string]$ScriptPath = ""
,[string]$StorageAccountName = ""
,[string]$StorageAccountKey = ""
,[string]$VMAdminUsername = ""
,[string]$NAVAdminUsername = ""
,[string]$AdminPassword = ""
,[string]$Country = "US"
,[string]$RestoreAndUseBakFile = "Default"
,[string]$CloudServiceName = ""
,[string]$LicenseFileUri = ""
,[string]$CertificatePfxUrl = ""
,[string]$CertificatePfxPassword = ""
,[string]$PublicMachineName = ""
,[string]$bingMapsKey = ""
,[string]$clickonce = ""
,[string]$powerBI = ""
,[string]$Office365UserName = ""
,[string]$Office365Password = ""
,[string]$Office365CreatePortal = ""
,[string]$Multitenancy = ""
,[string]$sqlAdminUsername = ""
,[string]$sqlServerName = ""
)
function Log([string]$line) { ('<font color="Gray">' + [DateTime]::Now.ToString([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern.replace(":mm",":mm:ss")) + " $line</font>") | Add-Content -Path "c:\demo\status.txt" }
if (Test-Path -Path "c:\DEMO\Status.txt" -PathType Leaf) {
Log "VM already initialized."
exit
}
Set-ExecutionPolicy -ExecutionPolicy unrestricted -Force
Start-Transcript -Path "C:\DEMO\initialize.txt"
([DateTime]::Now.ToString([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern.replace(":mm",":mm:ss")) + " Starting VM Initialization") | Add-Content -Path "c:\demo\status.txt"
function DownloadFile([string]$sourceUrl, [string]$destinationFile)
{
Log("Downloading '$sourceUrl' to '$destinationFile'")
Remove-Item -Path $destinationFile -Force -ErrorAction Ignore
Invoke-WebRequest $sourceUrl -OutFile $destinationFile
}
function PatchFileIfNecessary([string]$baseUrl, [string]$path, $date)
{
$destinationFile = ("C:\"+$path.Replace("/","\"))
$sourceUrl = "${baseUrl}$path"
if (Test-Path -path $destinationFile) {
if ((get-item $destinationFile).LastAccessTimeUtc.Date.CompareTo($date) -ne -1) {
# File is newer - don't patch
Log("Do not patch '$destinationFile' with '$sourceUrl'")
return
}
Remove-Item -Path $destinationFile -Force -ErrorAction Ignore
}
Log("Patching '$destinationFile' with '$sourceUrl'")
Invoke-WebRequest $sourceUrl -OutFile $destinationFile
}
# Other variables
$MachineName = [Environment]::MachineName.ToLowerInvariant()
new-item -Path "c:\DEMO\Install" -ItemType Directory -Force -ErrorAction Ignore
Log("Machine Name is $MachineName")
# Update RTM files
$date = (Get-Date -Date "2017-02-16 00:00:00Z").ToUniversalTime()
$PatchPath = $ScriptPath.SubString(0,$ScriptPath.LastIndexOf('/')+1)
#PatchFileIfNecessary -date $date -baseUrl "${PatchPath}Tenerife/" -path "DEMO/New Developer Experience/install.ps1"
if ($VMAdminUsername -eq "") {
Log("Restart computer and stop installation")
Restart-Computer -Force
}
# Download files for Task Registration
DownloadFile -SourceUrl "${PatchPath}InstallationTask.xml" -destinationFile "c:\DEMO\Install\InstallationTask.xml"
DownloadFile -SourceUrl "${PatchPath}StartInstallationTask.xml" -destinationFile "c:\DEMO\Install\StartInstallationTask.xml"
if ($CertificatePfxUrl -eq "")
{
$PublicMachineName = $CloudServiceName
$CertificatePfxFile = "default"
} else {
$CertificatePfxFile = "C:\DEMO\certificate.pfx"
if ($certificatePfxUrl.StartsWith("http://") -or $certificatePfxUrl.StartsWith("https://")) {
Write-Verbose "Downloading $certificatePfxUrl to $CertificatePfxFile"
DownloadFile -SourceUrl $certificatePfxUrl -destinationFile $CertificatePfxFile
} else {
Log("Unpack base64 encoded Certificate Pfx File to $certificatePfxFile")
# Assume Base64
[System.IO.File]::WriteAllBytes($CertificatePfxFile, [System.Convert]::FromBase64String($CertificatePfxUrl))
}
}
if ($LicenseFileUri -ne "")
{
$LicenseFile = "C:\DEMO\license.flf"
if ($LicenseFileUri.StartsWith("http://") -or $LicenseFileUri.StartsWith("https://")) {
Write-Verbose "Downloading $LicenseFileUri to $LicenseFile"
DownloadFile -SourceUrl $LicenseFileUri -destinationFile $LicenseFile
} else {
Log "Unpack base64 encoded Certificate Pfx File to $LicenseFile"
# Assume Base64
[System.IO.File]::WriteAllBytes($LicenseFile, [System.Convert]::FromBase64String($LicenseFileUri))
}
}
Log("Creating Installation Scripts")
$step = 1
$next = $step+1
('Unregister-ScheduledTask -TaskName "Start Installation Task" -Confirm:$false') | Add-Content "c:\DEMO\Install\step$step.ps1"
('function Log([string]$line) { (''<font color="Gray">'' + [DateTime]::Now.ToString([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern.replace(":mm",":mm:ss")) + " $line</font>") | Add-Content -Path "c:\demo\status.txt" }') | Add-Content "c:\DEMO\Install\step$step.ps1"
if ($NAVAdminUsername -ne "") {
# Initialize Virtual Machine
('Log("Waiting for NAV Service Tier to start")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. ("c:\program files\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('while ((Get-NAVServerInstance -ServerInstance NAV).State -ne "Running") { Start-Sleep -Seconds 5 }') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("NAV Service Tier started")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeLanguage = "'+$Country.Substring(0,2)+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeNavAdminUser = "'+$NAVAdminUsername+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeNavAdminPassword = "'+$AdminPassword+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeRestoreAndUseBakFile = "'+$RestoreAndUseBakFile+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeCloudServiceName = "'+$CloudServiceName+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodePublicMachineName = "'+$PublicMachineName+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodecertificatePfxFile = "'+$CertificatePfxFile+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodecertificatePfxPassword = "'+$CertificatePfxPassword+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Initializing Virtual Machine")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\Initialize\install.ps1" 4> "C:\DEMO\Initialize\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done initializing Virtual Machine")') | Add-Content "c:\DEMO\Install\step$step.ps1"
("Set-Content -Path ""c:\inetpub\wwwroot\http\$MachineName.rdp"" -Value 'full address:s:${PublicMachineName}:3389
prompt for credentials:i:1'") | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\initialize\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (Initialize): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if ($LicenseFileUri -ne "") {
# Initialize Virtual Machine
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeLicenseFile = "'+$LicenseFile+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeTranslateApiKey = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log "Installing Extensions Development Shell"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\Extensions\install.ps1"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log "Done installing Extensions Development Shell"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\Extensions\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log -kind Error ("Extensions: "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if ($Office365UserName -ne "") {
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeNavAdminUser = "'+$NAVAdminUsername+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointAdminLoginname = "'+$Office365UserName+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointAdminPassword = "'+$Office365Password+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeCreateSharePointPortal = "'+$Office365CreatePortal+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointUrl = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointSite = "' + ($PublicMachineName.Split('.')[0])+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointLanguage = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointTimezoneId = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointAppCatalogUrl = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeSharePointMultitenant = "No"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installing O365 integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\O365 Integration\install.ps1" 4> "C:\DEMO\O365 Integration\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done installing O365 integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\O365 Integration\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (O365): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if ($bingMapsKey -ne "") {
# Install BingMaps Integration
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeBingMapsKey = "'+$bingMapsKey+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeRegionFormat = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installing BingMaps integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\BingMaps\install.ps1" 4> "C:\DEMO\BingMaps\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done installing BingMaps integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\BingMaps\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (BingMaps): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if ($powerBI -eq "Yes") {
# Install PowerBI
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installing PowerBI integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\PowerBI\install.ps1" 4> "C:\DEMO\PowerBI\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done installing PowerBI integration")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\PowerBI\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (PowerBI): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if ($clickonce -eq "Yes") {
# Install ClickOnce
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installing ClickOnce deployment of Windows Client")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\Clickonce\install.ps1" 4> "C:\DEMO\Clickonce\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done installing ClickOnce deployment of Windows Client")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\Clickonce\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (ClickOnce): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
if (($sqlServerName -ne "") -and ($sqlAdminUsername -ne "")) {
# Setup Azure SQL
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Setting up Azure SQL")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeExistingAzureSqlDatabase = "Yes"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeDatabaseServer = "'+$sqlServerName+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeDatabaseUserName = "'+$sqlAdminUsername+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeDatabasePassword = "'+$adminPassword+'"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('$HardcodeDatabaseName = "default"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\AzureSQL\install.ps1" 4> "C:\DEMO\AzureSQL\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done setting up Azure SQL")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\AzureSQL\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (AzureSQL): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
}
('(''. "c:\DEMO\Install\Step'+$next+'.ps1"'') | Out-File "C:\DEMO\Install\Next-Step.ps1"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Register-ScheduledTask -Xml (get-content "c:\DEMO\Install\InstallationTask.xml" | out-string) -TaskName "Installation Task" -User "'+$VMAdminUserName+'" -Password "'+$AdminPassword+'" –Force') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Start-Sleep -seconds 10') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Restart-Computer -Force') | Add-Content "c:\DEMO\Install\step$step.ps1"
$step = $next
$next++
('function Log([string]$line) { ([DateTime]::Now.ToString([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern.replace(":mm",":mm:ss")) + " $line") | Add-Content -Path "c:\demo\status.txt" }') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Waiting for NAV Service Tier to start")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. ("c:\program files\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('while ((Get-NAVServerInstance -ServerInstance NAV).State -ne "Running") { Start-Sleep -Seconds 5 }') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("NAV Service Tier started")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('try {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installing New Developer Experience")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('. "c:\DEMO\New Developer Experience\install.ps1" 4> "C:\DEMO\New Developer Experience\install.log"') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Done installing New Developer Experience")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('} catch {') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Set-Content -Path "c:\DEMO\New Developer Experience\error.txt" -Value $_.Exception.Message') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("ERROR (New Dev Exp): "+$_.Exception.Message+" ("+($Error[0].ScriptStackTrace -split "\r\n")[0]+")")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('throw') | Add-Content "c:\DEMO\Install\step$step.ps1"
('}') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Cleaning up")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Remove-Item "c:\DEMO\Install" -Force -Recurse -ErrorAction Ignore') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Remove-Item "c:\DEMO\Initialize.txt" -Force -ErrorAction Ignore') | Add-Content "c:\DEMO\Install\step$step.ps1"
#('Unregister-ScheduledTask -TaskName "Installation Task" -Confirm:$false -ErrorAction Ignore') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Log("Installation complete")') | Add-Content "c:\DEMO\Install\step$step.ps1"
('Restart-Computer -Force') | Add-Content "c:\DEMO\Install\step$step.ps1"
Log("Register installation task")
Register-ScheduledTask -Xml (get-content "c:\DEMO\Install\StartInstallationTask.xml" | out-string) -TaskName "Start Installation Task" -User "NT AUTHORITY\SYSTEM" –Force
Log("Restart computer and start Installation tasks")
Restart-Computer -Force