forked from patrickperrone/Sitecore-PowerShell-Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
2827 lines (2453 loc) · 120 KB
/
install.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Specify a path to the .config file if you do not wish to put the .config file in the same directory as the script
$configPath = ""
$scriptDir = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)
$configSettings = $null
# Assume there is no host console available until we can read the config file.
$hostScreenAvailable = $FALSE
#region Utility Functions
function Write-Message([string]$Message, [string]$MessageColor="White", [bool]$WriteToLogOnly=$FALSE, [bool]$WriteToLog=$FALSE, [bool]$HostConsoleAvailable=$FALSE)
{
if (!([string]::IsNullOrEmpty($script:configSettings.SitecoreLogPath)) -and $WriteToLog)
{
# Write message to log file
Add-Content $logPath $Message
}
if (!$WriteToLogOnly)
{
if ($HostConsoleAvailable)
{
# Write message to screen
Write-Host $Message -ForegroundColor $MessageColor
}
else
{
# Write message to output stream
Write-Verbose $Message
}
}
}
function Remove-BackupFiles([System.Collections.Generic.List[string]]$backupFiles)
{
Write-Message "`nDeleting backed up files..." "Green" -WriteToLog $TRUE -HostConsoleAvailable $hostScreenAvailable
foreach ($file in $backupFiles)
{
Remove-Item $file
}
Write-Message "Removed back ups!" "White" -WriteToLog $TRUE -HostConsoleAvailable $hostScreenAvailable
}
function Read-InstallConfigFile([string]$configPath)
{
if ([string]::IsNullOrEmpty($configPath))
{
[xml]$configXml = Get-Content ($scriptDir + "\install.config")
}
else
{
if (Test-Path $configPath)
{
[xml]$configXml = Get-Content ($configPath)
}
else
{
Write-Message "Could not find configuration file at specified path: $confgPath" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
}
}
return $configXml
}
function Get-ConfigOption([xml]$config, [string]$optionName, [bool]$isAttribute=$FALSE)
{
$optionValue = $FALSE
if ($isAttribute)
{
$attributeName = Split-Path -Leaf $optionName
$optionName = Split-Path $optionName
$optionName = $optionName.Replace("\", "//")
$node = $config.InstallSettings.SelectSingleNode($optionName)
if ($node -ne $null)
{
$attributeValue = $node.GetAttribute($attributeName).Trim()
if (!([string]::IsNullOrEmpty($attributeValue)))
{
$optionValue = [System.Convert]::ToBoolean($attributeValue)
}
}
}
else
{
$nodeValue = $config.InstallSettings.SelectSingleNode($optionName).InnerText.Trim()
if (!([string]::IsNullOrEmpty($nodeValue)))
{
$optionValue = [System.Convert]::ToBoolean($nodeValue)
}
}
return $optionValue
}
function Get-SqlLoginAccountForDataAccess
{
# Top priority is Application Pool Identity
if ($script:configSettings.Database.UseWindowsAuthenticationForSqlDataAccess)
{
return $script:configSettings.WebServer.AppPoolIdentity
}
# Next, use the SQL login for data access if it exists
if (!([string]::IsNullOrEmpty($script:configSettings.Database.SqlLoginForDataAccess)))
{
return $script:configSettings.Database.SqlLoginForDataAccess
}
# Finally, use the Sql login for install, but only if it is not a domain account
$split = $script:configSettings.Database.SqlLoginForInstall.Split("\")
if ($split.Count -lt 2)
{
return $script:configSettings.Database.SqlLoginForInstall
}
else
{
Write-Message "The SqlLoginForInstall is a domain account and SqlLoginForDataAccess is undefined. You must supply a value for SqlLoginForDataAccess." "Yellow" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
}
return $null
}
function Get-SqlServerSmo
{
$sqlServerName = $script:configSettings.Database.SqlServerName
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null
$sqlServerSmo = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server $sqlServerName
# Set authentication to use login from config
$split = $script:configSettings.Database.SqlLoginForInstall.Split("\")
if ($split.Count -eq 2)
{
# Use Windows authentication
$sqlServerSmo.ConnectionContext.LoginSecure = $TRUE
$sqlServerSmo.ConnectionContext.ConnectAsUser = $TRUE
$sqlServerSmo.ConnectionContext.ConnectAsUserName = $split[1]
$sqlServerSmo.ConnectionContext.ConnectAsUserPassword = $script:configSettings.Database.SqlLoginForInstallPassword
}
else
{
# Use SQL authentication
$sqlServerSmo.ConnectionContext.LoginSecure = $FALSE
$sqlServerSmo.ConnectionContext.set_Login($script:configSettings.Database.SqlLoginForInstall)
$password = ConvertTo-SecureString $script:configSettings.Database.SqlLoginForInstallPassword -AsPlainText -Force
$sqlServerSmo.ConnectionContext.set_SecurePassword($password)
}
return $sqlServerSmo
}
function Get-DatabaseInstallFolderPath([bool]$localPath=$TRUE)
{
if ($localPath)
{
return $script:configSettings.Database.DatabaseInstallPath.Local
}
# Return the Local path if the Unc path does not exist
if ([string]::IsNullOrEmpty($script:configSettings.Database.DatabaseInstallPath.Unc))
{
return $script:configSettings.Database.DatabaseInstallPath.Local
}
return $script:configSettings.Database.DatabaseInstallPath.Unc
}
function Find-FolderInZipFile($items, [string]$folderName)
{
foreach($item in $items)
{
if ($item.GetFolder -ne $Null)
{
Find-FolderInZipFile $item.GetFolder.items() $folderName
}
if ($item.name -Like $folderName)
{
return $item
}
}
}
function Get-SitecoreVersion([bool]$getFromZip=$FALSE, [bool]$getFullVersion=$FALSE)
{
# Returns the version of the Sitecore.Kernel.dll
$installPath = Join-Path $script:configSettings.WebServer.SitecoreInstallRoot -ChildPath $script:configSettings.WebServer.SitecoreInstallFolder
$webrootPath = Join-Path $installPath -ChildPath "Website"
$kernelPath = Join-Path $webrootPath -ChildPath "bin\Sitecore.Kernel.dll"
if ($getFromZip)
{
if (!(Test-Path $installPath))
{
New-Item $installPath -type directory -force | Out-Null
}
$zipPath = $script:configSettings.SitecoreZipPath
$shell = New-Object -com shell.application
$item = Find-FolderInZipFile $shell.NameSpace($zipPath).Items() "bin"
$kernelItem = $shell.NameSpace($item.Path).Items() | Where {$_.Name -match "Sitecore.Kernel.dll"}
$shell.NameSpace($installPath).CopyHere($kernelItem)
$path = Join-Path $installPath -ChildPath $kernelItem.Name
$fullVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path).FileVersion
Remove-Item $path
}
else
{
$fullVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($kernelPath).FileVersion
}
$versionInfo = $fullVersion
if (!$getFullVersion)
{
$verArr = $fullVersion.Split("{.}")
$versionInfo = "{0}.{1}" -f $verArr[0],$verArr[1]
}
return $versionInfo
}
function Get-BaseConnectionString
{
$sqlServerName = $script:configSettings.Database.SqlServerName
if ($script:configSettings.Database.UseWindowsAuthenticationForSqlDataAccess)
{
$baseConnectionString = "Server=$sqlServerName;Trusted_Connection=Yes;Database="
}
else
{
if ([string]::IsNullOrEmpty($script:configSettings.Database.SqlLoginForDataAccess))
{
$loginName = $script:configSettings.Database.SqlLoginForInstall
$loginPassword = $script:configSettings.Database.SqlLoginForInstallPassword
}
else
{
$loginName = $script:configSettings.Database.SqlLoginForDataAccess
$loginPassword = $script:configSettings.Database.SqlLoginForDataAccessPassword
}
$baseConnectionString = "user id=$loginName;password=$loginPassword;Data Source=$sqlServerName;Database="
}
return $baseConnectionString
}
function Get-SubstituteDatabaseFileName($currentFileName, $dbName)
{
# Function assumes name format will be Sitecore.{$dbname}.{ldf|mdf}
$prefix = $currentFileName.Substring(0,8)
$suffix = $currentFileName.Substring($currentFileName.Length-3)
return ("{0}.{1}.{2}" -f $prefix,$dbName,$suffix)
}
function Set-AclForFolder([string]$userName, [string]$permission, [string]$folderPath)
{
$acl = Get-Acl $folderPath
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userName, $permission, "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule)
Set-Acl $folderPath $acl
Write-Message "Added $userName to ACL ($permission) for $folderPath" "White" -WriteToLog $TRUE -HostConsoleAvailable $hostScreenAvailable
}
function Test-IsUserMemberOfLocalGroup([string]$groupName, [string]$userName)
{
$group =[ADSI]"WinNT://$env:COMPUTERNAME/$groupName,group"
$members = @($group.psbase.Invoke("Members"))
foreach ($member in $members)
{
$memberName = $member.GetType().InvokeMember("Name", 'GetProperty', $null, $member, $null)
if ($memberName -eq $userName)
{
return $TRUE
}
}
return $FALSE
}
function Add-CalculatedPropertiesToConfigurationSettings
{
# WebServer.SitecoreInstallPath
$sitecoreInstallPath = Join-Path $script:configSettings.WebServer.SitecoreInstallRoot -ChildPath $script:configSettings.WebServer.SitecoreInstallFolder
$script:configSettings.WebServer | Add-Member -MemberType NoteProperty -Name SitecoreInstallPath -Value $sitecoreInstallPath
# WebServer.SitecoreLogPath
$sitecoreLogPath = ""
if (!([string]::IsNullOrEmpty($script:configSettings.LogFileName)))
{
$sitecoreLogPath = Join-path $script:configSettings.WebServer.SitecoreInstallPath -ChildPath $script:configSettings.LogFileName
}
$script:configSettings.WebServer | Add-Member -MemberType NoteProperty -Name SitecoreLogPath -Value $sitecoreLogPath
# Database.BaseConnectionString
$script:configSettings.Database | Add-Member -MemberType NoteProperty -Name BaseConnectionString -Value (Get-BaseConnectionString)
}
function New-ConfigSettings([xml]$config)
{
#region WebServer
#region IISBindings
$iisbindings = New-Object 'System.Collections.Generic.List[PSObject]'
foreach ($binding in ($config.InstallSettings.WebServer.IISBindings.Binding))
{
$b = New-Object -TypeName PSObject
$ip = $binding.IP
if (!([string]::IsNullOrEmpty($ip)))
{
$ip = $ip.Trim()
}
[int]$port = $binding.Port
$hostheader = $binding.HostHeader
if (!([string]::IsNullOrEmpty($hostheader)))
{
$hostheader = $hostheader.Trim()
}
[bool]$addToHostsFile = [System.Convert]::ToBoolean($binding.AddToHostsFile)
$b | Add-Member -MemberType NoteProperty -Name IP -Value $ip
$b | Add-Member -MemberType NoteProperty -Name Port -Value $port
$b | Add-Member -MemberType NoteProperty -Name HostHeader -Value $hostheader
$b | Add-Member -MemberType NoteProperty -Name AddToHostsFile -Value $addToHostsFile
$iisBindings.Add($b)
}
#endregion
#region CMServerSettings
$parallel = New-Object -TypeName PSObject
[int]$growthsize = $config.InstallSettings.WebServer.CMServerSettings.Publishing.Parallel.WebDatabaseAutoGrowthInMB
[int]$degrees = $config.InstallSettings.WebServer.CMServerSettings.Publishing.Parallel.MaxDegreesOfParallelism
$parallel | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "WebServer/CMServerSettings/Publishing/Parallel/enabled" $TRUE)
$parallel | Add-Member -MemberType NoteProperty -Name WebDatabaseAutoGrowthInMB -Value $growthsize
$parallel | Add-Member -MemberType NoteProperty -Name MaxDegreesOfParallelism -Value $degrees
$publishing = New-Object -TypeName PSObject
$publishingInstance = $config.InstallSettings.WebServer.CMServerSettings.Publishing.PublishingInstance
if (!([string]::IsNullOrEmpty($publishingInstance)))
{
$publishingInstance = $publishingInstance.Trim()
}
$appPoolIdleTimeout = $config.InstallSettings.WebServer.CMServerSettings.Publishing.AppPoolIdleTimeout
if (!([string]::IsNullOrEmpty($appPoolIdleTimeout)))
{
$appPoolIdleTimeout = $appPoolIdleTimeout.Trim()
}
$publishing | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "WebServer/CMServerSettings/Publishing/enabled" $TRUE)
$publishing | Add-Member -MemberType NoteProperty -Name PublishingInstance -Value $publishingInstance
$publishing | Add-Member -MemberType NoteProperty -Name AppPoolIdleTimeout -Value $appPoolIdleTimeout
$publishing | Add-Member -MemberType NoteProperty -Name Parallel -Value $parallel
$cmServerSettings = New-Object -TypeName PSObject
$instanceName = $config.InstallSettings.WebServer.CMServerSettings.InstanceName
if (!([string]::IsNullOrEmpty($instanceName)))
{
$instanceName = $instanceName.Trim()
}
$adminPassword = $config.InstallSettings.WebServer.CMServerSettings.DefaultSitecoreAdminPassword
if (!([string]::IsNullOrEmpty($adminPassword)))
{
$adminPassword = $adminPassword.Trim()
}
$cmServerSettings | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "WebServer/CMServerSettings/enabled" $TRUE)
$cmServerSettings | Add-Member -MemberType NoteProperty -Name InstanceName -Value $instanceName
$cmServerSettings | Add-Member -MemberType NoteProperty -Name DefaultSitecoreAdminPassword -Value $adminPassword
$cmServerSettings | Add-Member -MemberType NoteProperty -Name Publishing -Value $publishing
#endregion
#region CDServerSettings
$cdServerSettings = New-Object -TypeName PSObject
$cdServerSettings | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "WebServer/CDServerSettings/enabled" $TRUE)
$cdServerSettings | Add-Member -MemberType NoteProperty -Name ApplyIPWhitelist -Value (Get-ConfigOption $config "WebServer/CDServerSettings/ApplyIPWhitelist")
$cdServerSettings | Add-Member -MemberType NoteProperty -Name DeactivateConnectionStrings -Value (Get-ConfigOption $config "WebServer/CDServerSettings/DeactivateConnectionStrings")
$cdServerSettings | Add-Member -MemberType NoteProperty -Name ConfigureFilesForCD -Value (Get-ConfigOption $config "WebServer/CDServerSettings/ConfigureFilesForCD")
$cdServerSettings | Add-Member -MemberType NoteProperty -Name PreventAnonymousAccess -Value (Get-ConfigOption $config "WebServer/CDServerSettings/PreventAnonymousAccess")
$cdServerSettings | Add-Member -MemberType NoteProperty -Name DenyExecutePermission -Value (Get-ConfigOption $config "WebServer/CDServerSettings/DenyExecutePermission")
$cdServerSettings | Add-Member -MemberType NoteProperty -Name DisableUploadWatcher -Value (Get-ConfigOption $config "WebServer/CDServerSettings/DisableUploadWatcher")
#endregion
#region IPWhiteList
$ipWhiteList = New-Object 'System.Collections.Generic.List[string]'
foreach ($ip in ($config.InstallSettings.WebServer.IPWhiteList.IP))
{
$ipValue = $ip
if (!([string]::IsNullOrEmpty($ipValue)))
{
$ipValue = $ipValue.Trim()
}
$ipWhiteList.Add($ipValue)
}
#endregion
#region SessionStateProvider
$sessionStateProvider = New-Object -TypeName PSObject
$private = $config.InstallSettings.WebServer.SessionStateProvider.Private
if (!([string]::IsNullOrEmpty($private)))
{
$private = $private.Trim()
}
$shared = $config.InstallSettings.WebServer.SessionStateProvider.Shared
if (!([string]::IsNullOrEmpty($shared)))
{
$shared = $shared.Trim()
}
$sessionStateProvider | Add-Member -MemberType NoteProperty -Name Private -Value $private
$sessionStateProvider | Add-Member -MemberType NoteProperty -Name Shared -Value $shared
#endregion
#region Solr
$solr = New-Object -TypeName PSObject
$serviceBaseAddress = $config.InstallSettings.WebServer.Solr.ServiceBaseAddress
if (!([string]::IsNullOrEmpty($serviceBaseAddress)))
{
$serviceBaseAddress = $serviceBaseAddress.Trim()
}
$solr | Add-Member -MemberType NoteProperty -Name ServiceBaseAddress -Value $serviceBaseAddress
#endregion
#region MongoDb
$credentials = New-Object -TypeName PSObject
$username = $config.InstallSettings.WebServer.MongoDb.Credentials.Username
if (!([string]::IsNullOrEmpty($username)))
{
$username = $username.Trim()
}
$password = $config.InstallSettings.WebServer.MongoDb.Credentials.Password
if (!([string]::IsNullOrEmpty($password)))
{
$password = $password.Trim()
}
$credentials | Add-Member -MemberType NoteProperty -Name Username -Value $username
$credentials | Add-Member -MemberType NoteProperty -Name Password -Value $password
$hosts = New-Object 'System.Collections.Generic.List[PSObject]'
foreach ($mongohost in ($config.InstallSettings.WebServer.MongoDb.Hosts.Host))
{
$h = New-Object -TypeName PSObject
$hostname = $mongohost.HostName
if (!([string]::IsNullOrEmpty($hostname)))
{
$hostname = $hostname.Trim()
}
[int]$port = $mongohost.Port
$h | Add-Member -MemberType NoteProperty -Name HostName -Value $hostname
$h | Add-Member -MemberType NoteProperty -Name Port -Value $port
$hosts.Add($h)
}
$mongodb = New-Object -TypeName PSObject
$options = $config.InstallSettings.WebServer.MongoDb.Options
if (!([string]::IsNullOrEmpty($options)))
{
$options = $options.Trim()
}
$mongodb | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "WebServer/MongoDb/enabled" $TRUE)
$mongodb | Add-Member -MemberType NoteProperty -Name Credentials -Value $credentials
$mongodb | Add-Member -MemberType NoteProperty -Name Hosts -Value $hosts
$mongodb | Add-Member -MemberType NoteProperty -Name Options -Value $options
#endregion
$webserver = New-Object -TypeName PSObject
$licenseFilePath = $config.InstallSettings.WebServer.LicenseFilePath
if (!([string]::IsNullOrEmpty($licenseFilePath)))
{
$licenseFilePath = $licenseFilePath.Trim()
}
$sitecoreInstallRoot = $config.InstallSettings.WebServer.SitecoreInstallRoot
if (!([string]::IsNullOrEmpty($sitecoreInstallRoot)))
{
$sitecoreInstallRoot = $sitecoreInstallRoot.Trim()
}
$sitecoreInstallFolder = $config.InstallSettings.WebServer.SitecoreInstallFolder
if (!([string]::IsNullOrEmpty($sitecoreInstallFolder)))
{
$sitecoreInstallFolder = $sitecoreInstallFolder.Trim()
}
$lastChildFolderOfIncludeDirectory = $config.InstallSettings.WebServer.LastChildFolderOfIncludeDirectory
if (!([string]::IsNullOrEmpty($lastChildFolderOfIncludeDirectory)))
{
$lastChildFolderOfIncludeDirectory = $lastChildFolderOfIncludeDirectory.Trim()
}
$iisWebSiteName = $config.InstallSettings.WebServer.IISWebSiteName
if (!([string]::IsNullOrEmpty($iisWebSiteName)))
{
$iisWebSiteName = $iisWebSiteName.Trim()
}
$defaultRuntimeVersion = $config.InstallSettings.WebServer.DefaultRuntimeVersion
if (!([string]::IsNullOrEmpty($defaultRuntimeVersion)))
{
$defaultRuntimeVersion = $defaultRuntimeVersion.Trim()
}
$appPoolIdentity = $config.InstallSettings.WebServer.AppPoolIdentity
if (!([string]::IsNullOrEmpty($appPoolIdentity)))
{
$appPoolIdentity = $appPoolIdentity.Trim()
}
$appPoolIdentityPassword = $config.InstallSettings.WebServer.AppPoolIdentityPassword
if (!([string]::IsNullOrEmpty($appPoolIdentityPassword)))
{
$appPoolIdentityPassword = $appPoolIdentityPassword.Trim()
}
$webserver | Add-Member -MemberType NoteProperty -Name LicenseFilePath -Value $licenseFilePath
$webserver | Add-Member -MemberType NoteProperty -Name SitecoreInstallRoot -Value $sitecoreInstallRoot
$webserver | Add-Member -MemberType NoteProperty -Name SitecoreInstallFolder -Value $sitecoreInstallFolder
$webserver | Add-Member -MemberType NoteProperty -Name LastChildFolderOfIncludeDirectory -Value $lastChildFolderOfIncludeDirectory
$webserver | Add-Member -MemberType NoteProperty -Name IISWebSiteName -Value $iisWebSiteName
$webserver | Add-Member -MemberType NoteProperty -Name DefaultRuntimeVersion -Value $defaultRuntimeVersion
$webserver | Add-Member -MemberType NoteProperty -Name AppPoolIdentity -Value $appPoolIdentity
$webserver | Add-Member -MemberType NoteProperty -Name AppPoolIdentityPassword -Value $appPoolIdentityPassword
$webserver | Add-Member -MemberType NoteProperty -Name IISBindings -Value $iisbindings
$webserver | Add-Member -MemberType NoteProperty -Name CMServerSettings -Value $cmServerSettings
$webserver | Add-Member -MemberType NoteProperty -Name CDServerSettings -Value $cdServerSettings
$webserver | Add-Member -MemberType NoteProperty -Name IPWhiteList -Value $ipWhiteList
$webserver | Add-Member -MemberType NoteProperty -Name SessionStateProvider -Value $sessionStateProvider
$webserver | Add-Member -MemberType NoteProperty -Name Solr -Value $solr
$webserver | Add-Member -MemberType NoteProperty -Name MongoDb -Value $mongodb
#endregion
#region Database
#region DatabaseNames
$databases = New-Object 'System.Collections.Generic.List[PSObject]'
foreach ($dbname in ($config.InstallSettings.Database.DatabaseNames.name))
{
$db = New-Object -TypeName PSObject
$name = $dbname
if (!([string]::IsNullOrEmpty($name)))
{
$name = $name.Trim()
}
$db | Add-Member -MemberType NoteProperty -Name Name -Value $name
$db | Add-Member -MemberType NoteProperty -Name ConnectionStringName -Value $name.ToLower()
$databases.Add($db)
}
#endregion
#region WebDatabaseCopies
$webDatabaseCopies = New-Object 'System.Collections.Generic.List[PSObject]'
foreach ($copy in ($config.InstallSettings.Database.WebDatabaseCopies.copy))
{
$db = New-Object -TypeName PSObject
if ($copy.GetType().Name -eq "String")
{
$copyname = $copy
}
else
{
$copyname = $copy.InnerText
}
if (!([string]::IsNullOrEmpty($copyname)))
{
$copyname = $copyname.Trim()
}
$connectionStringName = $copy.connectionStringName
if ([string]::IsNullOrEmpty($connectionStringName))
{
$connectionStringName = $copyname.ToLower()
}
else
{
$connectionStringName = $connectionStringName.Trim()
}
$db | Add-Member -MemberType NoteProperty -Name Name -Value $copyname
$db | Add-Member -MemberType NoteProperty -Name ConnectionStringName -Value $connectionStringName
$webDatabaseCopies.Add($db)
}
#endregion
#region DatabaseInstallPath
$databaseInstallPath = New-Object -TypeName PSObject
$local = $config.InstallSettings.Database.DatabaseInstallPath.Local
if (!([string]::IsNullOrEmpty($local)))
{
$local = $local.Trim()
}
$unc = $config.InstallSettings.Database.DatabaseInstallPath.Unc
if (!([string]::IsNullOrEmpty($unc)))
{
$unc = $unc.Trim()
}
$databaseInstallPath | Add-Member -MemberType NoteProperty -Name Local -Value $local
$databaseInstallPath | Add-Member -MemberType NoteProperty -Name Unc -Value $unc
#endregion
$database = New-Object -TypeName PSObject
$sqlServerName = $config.InstallSettings.Database.SqlServerName
if (!([string]::IsNullOrEmpty($sqlServerName)))
{
$sqlServerName = $sqlServerName.Trim()
}
$sqlLoginForInstall = $config.InstallSettings.Database.SqlLoginForInstall
if (!([string]::IsNullOrEmpty($sqlLoginForInstall)))
{
$sqlLoginForInstall = $sqlLoginForInstall.Trim()
}
$sqlLoginForInstallPassword = $config.InstallSettings.Database.SqlLoginForInstallPassword
if (!([string]::IsNullOrEmpty($sqlLoginForInstallPassword)))
{
$sqlLoginForInstallPassword = $sqlLoginForInstallPassword.Trim()
}
$sqlLoginForDataAccess = $config.InstallSettings.Database.SqlLoginForDataAccess
if (!([string]::IsNullOrEmpty($sqlLoginForDataAccess)))
{
$sqlLoginForDataAccess = $sqlLoginForDataAccess.Trim()
}
$sqlLoginForDataAccessPassword = $config.InstallSettings.Database.SqlLoginForDataAccessPassword
if (!([string]::IsNullOrEmpty($sqlLoginForDataAccessPassword)))
{
$sqlLoginForDataAccessPassword = $sqlLoginForDataAccessPassword.Trim()
}
$databaseNamePrefix = $config.InstallSettings.Database.DatabaseNamePrefix
if (!([string]::IsNullOrEmpty($databaseNamePrefix)))
{
$databaseNamePrefix = $databaseNamePrefix.Trim()
}
$database | Add-Member -MemberType NoteProperty -Name Enabled -Value (Get-ConfigOption $config "Database/enabled" $TRUE)
$database | Add-Member -MemberType NoteProperty -Name InstallDatabase -Value (Get-ConfigOption $config "Database/InstallDatabase")
$database | Add-Member -MemberType NoteProperty -Name Databases -Value $databases
$database | Add-Member -MemberType NoteProperty -Name WebDatabaseCopies -Value $webDatabaseCopies
$database | Add-Member -MemberType NoteProperty -Name SqlServerName -Value $sqlServerName
$database | Add-Member -MemberType NoteProperty -Name SqlLoginForInstall -Value $sqlLoginForInstall
$database | Add-Member -MemberType NoteProperty -Name SqlLoginForInstallPassword -Value $sqlLoginForInstallPassword
$database | Add-Member -MemberType NoteProperty -Name SqlLoginForDataAccess -Value $sqlLoginForDataAccess
$database | Add-Member -MemberType NoteProperty -Name SqlLoginForDataAccessPassword -Value $sqlLoginForDataAccessPassword
$database | Add-Member -MemberType NoteProperty -Name UseWindowsAuthenticationForSqlDataAccess -Value (Get-ConfigOption $config "Database/UseWindowsAuthenticationForSqlDataAccess")
$database | Add-Member -MemberType NoteProperty -Name DatabaseInstallPath -Value $databaseInstallPath
$database | Add-Member -MemberType NoteProperty -Name DatabaseNamePrefix -Value $databaseNamePrefix
#endregion
$script:configSettings = New-Object -TypeName PSObject
$logFileName = $config.InstallSettings.LogFileName
if (!([string]::IsNullOrEmpty($logFileName)))
{
$logFileName = $logFileName.Trim()
}
$sitecoreZipPath = $config.InstallSettings.SitecoreZipPath
if (!([string]::IsNullOrEmpty($sitecoreZipPath)))
{
$sitecoreZipPath = $sitecoreZipPath.Trim()
}
$script:configSettings | Add-Member -MemberType NoteProperty -Name LogFileName -Value $logFileName
$script:configSettings | Add-Member -MemberType NoteProperty -Name SitecoreZipPath -Value $sitecoreZipPath
$script:configSettings | Add-Member -MemberType NoteProperty -Name SuppressPrompts -Value (Get-ConfigOption $config "SuppressPrompts")
$script:configSettings | Add-Member -MemberType NoteProperty -Name WebServer -Value $webserver
$script:configSettings | Add-Member -MemberType NoteProperty -Name Database -Value $database
}
#endregion
#region Sanity Checks
function Test-Module([string]$name)
{
if(-not(Get-Module -name $name))
{
if(Get-Module -ListAvailable | Where-Object { $_.name -eq $name })
{
Write-Message "Importing $name module." "Gray" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
Import-Module -Name $name -DisableNameChecking
Write-Message "`n" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
$TRUE
}
else
{
$FALSE
}
}
else
{
Write-Message "$name module is already imported.`n" "Gray" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
$TRUE
}
}
function Test-PreRequisites
{
Write-Message "Testing script pre-requisites." "Gray" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (!($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )))
{
Write-Message "Warning: PowerShell must run as an Administrator." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
$moduleName = "SQLPS"
if (!(Test-Module $moduleName))
{
Write-Message "Warning: SQL PowerShell Module ($moduleName) is not installed." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
else
{
Set-Location -Path $scriptDir
}
$moduleName = "WebAdministration"
if (!(Test-Module $moduleName))
{
Write-Message "Warning: IIS PowerShell Module ($moduleName) is not installed." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
return $TRUE
}
function Test-SqlLoginConfiguration
{
$login = Get-SqlLoginAccountForDataAccess
if ($login -eq $null)
{
return $FALSE
}
return $TRUE
}
function Test-MemberOfRole([string]$memberName, [string]$roleName, [Microsoft.SqlServer.Management.Smo.Server]$sqlServerSmo)
{
$roleMembers = $sqlServerSmo.Roles[$roleName].EnumServerRoleMembers()
if ($roleMembers | Where-Object { $memberName -contains $_ })
{
return $TRUE
}
else
{
$FALSE
}
}
function Test-SqlConnectionAndRoles
{
[Microsoft.SqlServer.Management.Smo.Server]$sqlServerSmo = Get-SqlServerSmo
try
{
# Validate SQL connection can be established
$sqlServerSmo.ConnectionContext.Connect()
# Validate server roles for install login: must be sysadmin
$memberName = $script:configSettings.Database.SqlLoginForInstall
$isSysAdmin = Test-MemberOfRole $memberName "sysadmin" $sqlServerSmo
if (!$isSysAdmin)
{
Write-Message "$memberName doesn't have required server roles in SQL" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
Write-Message "Grant the sysadmin role to $memberName" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
# Validate data access login exists
$loginName = Get-SqlLoginAccountForDataAccess
if ($sqlServerSmo.Logins[$loginName] -eq $null)
{
Write-Message "Could not find a login called $loginName on SQL server" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
return $TRUE
}
catch [Exception]
{
Write-Message ($_.Exception) "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
function Test-SqlInstallPath
{
# Check that path exists
$dbInstallPath = Get-DatabaseInstallFolderPath $FALSE
if (Test-Path $dbInstallPath)
{
# Check that SQL has correct rights over install path, else Database Attach will fail
[Microsoft.SqlServer.Management.Smo.Server]$sqlServerSmo = Get-SqlServerSmo
$user = $sqlServerSmo.SqlDomainGroup
$acl = Get-Acl $dbInstallPath
$isCorrectRights = $acl.Access | Where {($_.IdentityReference -eq $user) -and ($_.FileSystemRights -eq "FullControl")}
if($isCorrectRights)
{
return $TRUE
}
else
{
Write-Message "SQL doesn't appear to have enough rights for the install path." "Yellow" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
Write-Message "This might be because SQL is using builtin virtual service accounts, which are local accounts that exist on a different server than the Sitecore server. If this is true, you may IGNORE this message." "Yellow" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
Write-Message "Ensure that the SQL service for your SQL instance has FullControl of $dbInstallPath" "Yellow" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
Write-Message "Failure to do so will PREVENT the databases from attaching.`n" "Yellow" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
if ($script:configSettings.SuppressPrompts)
{
return $TRUE
}
else
{
$shell = new-object -comobject "WScript.Shell"
$result = $shell.popup("Do you wish to proceed?",0,"Question",4+32)
# $result will be 6 for yes, 7 for no.
if ($result -eq 6)
{
return $TRUE
}
}
}
}
else
{
Write-Message "Path does not exist: $dbInstallPath" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
}
return $FALSE
}
function Test-WebDatabseCopyNames
{
$dbCopies = $script:configSettings.Database.WebDatabaseCopies
if ($dbCopies.Count -ne ($dbCopies | Select Name -Unique | measure).Count)
{
Write-Message "The name of a web database copy was repeated in the config file." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
if ($dbCopies.Count -ne ($dbCopies | Select ConnectionStringName -Unique | measure).Count)
{
Write-Message "The value of the connectionStringName attribute for a web database copy was repeated in the config file." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
if ($dbCopies | Where-Object {$_.Name.ToLower() -eq "web"})
{
Write-Message "Cannot use 'web' (name is case-insensitive) as the name of a web database copy." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
return $TRUE
}
function Test-IISBindings
{
foreach ($binding in $script:configSettings.WebServer.IISBindings)
{
if ($binding.IP.Length -eq 0)
{
Write-Message "Binding must contain a non-empty IP attribute." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
if ($binding.IP -ne "*" -and !([bool]($binding.IP -as [ipaddress])))
{
Write-Message "Binding's IP attribute must either be a valid IP or the '*' character." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
if ($binding.Port.Length -eq 0)
{
Write-Message "Binding must contain a non-empty Port attribute." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
if ($binding.Port -lt 1 -or $binding.Port -gt 65535)
{
Write-Message "Binding Port must be in the range 1-65535." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
return $TRUE
}
function Test-PublishingServerRole
{
if ($script:configSettings.WebServer.CMServerSettings.Enabled)
{
return ($script:configSettings.WebServer.CMServerSettings.Publishing.Enabled)
}
return $FALSE
}
function Test-SupportedSitecoreVersion
{
$versionToInstall = Get-SitecoreVersion $TRUE
if ($versionToInstall -eq "8.0")
{
return $TRUE
}
elseif ($versionToInstall -eq "8.1")
{
return $TRUE
}
return $FALSE
}
function Test-MongoDbConfiguration
{
if ($script:configSettings.WebServer.MongoDb.Enabled)
{
$username = $script:configSettings.WebServer.MongoDb.Credentials.Username
$password = $script:configSettings.WebServer.MongoDb.Credentials.Password
if (!([string]::IsNullOrEmpty($username)))
{
if ([string]::IsNullOrEmpty($password))
{
Write-Message "A username was given without a password for MongoDB. The password cannot be blank." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
if (!([string]::IsNullOrEmpty($password)))
{
if ([string]::IsNullOrEmpty($username))
{
Write-Message "A password was given without a username for MongoDB. The username cannot be blank." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
$numhosts = 0
foreach ($mongohost in $script:configSettings.WebServer.MongoDb.Hosts)
{
if ($mongohost.HostName.Length -eq 0)
{
Write-Message "MongoDB HostName must cannot be empty." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
else
{
$numhosts++
}
if ($mongohost.Port -lt 1 -or $mongohost.Port -gt 65535)
{
Write-Message "MongoDB host Port must be in the range 1-65535." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
if ($numhosts -lt 1)
{
Write-Message "MongoDB requies at least one Host to be specified." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
return $TRUE
}
function Test-SessionStateConfiguration
{
if ($script:configSettings.WebServer.CMServerSettings.Enabled)
{
if ($script:configSettings.WebServer.SessionStateProvider.Shared.ToLower() -ne "inproc")
{
Write-Message "Out of proc shared session state providers are not supported on CMs. You must use the inproc provider." "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
}
$sessionStateProvider = $script:configSettings.WebServer.SessionStateProvider.Private.ToLower()
if ($sessionStateProvider -eq "mongo")
{
Write-Message "Mongo is not currently supported by installer for a private SessionStateProvider" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
elseif ($sessionStateProvider -ne "inproc" -and $sessionStateProvider -ne "mssql")
{
Write-Message "Private SessionStateProvider selection is not recognized" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE
}
$sessionStateProvider = $script:configSettings.WebServer.SessionStateProvider.Shared.ToLower()
if ($sessionStateProvider -eq "mongo")
{
Write-Message "Mongo is not currently supported by installer for a shared SessionStateProvider" "Red" -WriteToLog $FALSE -HostConsoleAvailable $hostScreenAvailable
return $FALSE