forked from brianlala/AutoSPInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoSPInstallerModule.psm1
More file actions
7776 lines (7492 loc) · 450 KB
/
AutoSPInstallerModule.psm1
File metadata and controls
7776 lines (7492 loc) · 450 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
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
# ===================================================================================
# EXTERNAL FUNCTIONS
# ===================================================================================
# Check that the version of the script matches the Version (essentially the schema) of the input XML so we don't have any unexpected behavior
Function CheckXMLVersion ([xml]$xmlInput)
{
$getXMLVersion = $xmlInput.Configuration.Version
# The value below will increment whenever there is an update to the format of the AutoSPInstallerInput XML file
$scriptCurrentVersion = "3.99.60"
$scriptPreviousVersion = "3.99.51"
if ($getXMLVersion -ne $scriptCurrentVersion)
{
if ($getXMLVersion -eq $scriptPreviousVersion)
{
Write-Host -ForegroundColor Yellow " - Warning! Your input XML version ($getXMLVersion) is one level behind the script's version."
Write-Host -ForegroundColor Yellow " - Visit https://autospinstaller.com to update it to the current version before proceeding."
}
else
{
Write-Host -ForegroundColor Yellow " - Warning! Your versions of the XML ($getXMLVersion) and script ($scriptCurrentVersion) are mismatched."
Write-Host -ForegroundColor Yellow " - You should compare against the latest AutoSPInstallerInput.XML for missing/updated elements."
Write-Host -ForegroundColor Yellow " - Or, try to validate/update your XML input at https://autospinstaller.com"
}
Pause "proceed with running AutoSPInstaller if you are sure this is OK, or Ctrl-C to exit" "y"
}
}
#region Validate Passphrase
Function ValidatePassphrase ([xml]$xmlInput)
{
# Check if passphrase is supplied
$farmPassphrase = $xmlInput.Configuration.Farm.Passphrase
If (!($farmPassphrase) -or ($farmPassphrase -eq ""))
{
Return
}
$groups=0
If ($farmPassphrase -cmatch "[a-z]") { $groups = $groups + 1 }
If ($farmPassphrase -cmatch "[A-Z]") { $groups = $groups + 1 }
If ($farmPassphrase -match "[0-9]") { $groups = $groups + 1 }
If ($farmPassphrase -match "[^a-zA-Z0-9]") { $groups = $groups + 1 }
If (($groups -lt 3) -or ($farmPassphrase.length -lt 8))
{
Write-Host -ForegroundColor Yellow " - Farm passphrase does not meet complexity requirements."
Write-Host -ForegroundColor Yellow " - It must be at least 8 characters long and contain three of these types:"
Write-Host -ForegroundColor Yellow " - Upper case letters"
Write-Host -ForegroundColor Yellow " - Lower case letters"
Write-Host -ForegroundColor Yellow " - Digits"
Write-Host -ForegroundColor Yellow " - Other characters"
Throw " - Farm passphrase does not meet complexity requirements."
}
}
#endregion
#region Validate Credentials
Function ValidateCredentials ([xml]$xmlInput)
{
WriteLine
Write-Host -ForegroundColor White " - Validating user accounts and passwords..."
If ($env:COMPUTERNAME -eq $env:USERDOMAIN)
{
Throw " - You are running this script under a local machine user account. You must be a domain user"
}
ForEach($node in $xmlInput.SelectNodes("//*[@Password]|//*[@password]|//*[@ContentAccessAccountPassword]|//*[@UnattendedIDPassword]|//*[@SyncConnectionAccountPassword]|//*[Password]|//*[password]|//*[ContentAccessAccountPassword]|//*[UnattendedIDPassword]|//*[SyncConnectionAccountPassword]"))
{
$user = (GetFromNode $node "username")
If ($user -eq "") { $user = (GetFromNode $node "Username") }
If ($user -eq "") { $user = (GetFromNode $node "Account") }
If ($user -eq "") { $user = (GetFromNode $node "ContentAccessAccount") }
If ($user -eq "") { $user = (GetFromNode $node "UnattendedIDUser") }
If ($user -eq "") { $user = (GetFromNode $node "SyncConnectionAccount") }
$password = (GetFromNode $node "password")
If ($password -eq "") { $password = (GetFromNode $node "Password") }
If ($password -eq "") { $password = (GetFromNode $node "ContentAccessAccountPassword") }
If ($password -eq "") { $password = (GetFromNode $node "UnattendedIDPassword") }
If ($password -eq "") { $password = (GetFromNode $node "SyncConnectionAccountPassword") }
If (($password -ne "") -and ($user -ne ""))
{
$currentDomain = "LDAP://" + ([ADSI]"").distinguishedName
Write-Host -ForegroundColor White " - Account `"$user`" ($($node.Name))..." -NoNewline
$dom = New-Object System.DirectoryServices.DirectoryEntry($currentDomain,$user,$password)
If ($dom.Path -eq $null)
{
Write-Host -BackgroundColor Red -ForegroundColor Black "Invalid!"
$acctInvalid = $true
}
Else
{
Write-Host -ForegroundColor Black -BackgroundColor Green "Verified."
}
}
}
if ($xmlInput.Configuration.WebApplications)
{
# Get application pool accounts
foreach ($webApp in $($xmlInput.Configuration.WebApplications.WebApplication))
{
$appPoolAccounts = @($appPoolAccounts+$webApp.applicationPoolAccount)
# Get site collection owners #
foreach ($siteCollection in $($webApp.SiteCollections.SiteCollection))
{
if (!([string]::IsNullOrEmpty($siteCollection.Owner)))
{
$siteCollectionOwners = @($siteCollectionOwners+$siteCollection.Owner)
}
}
}
}
$appPoolAccounts = $appPoolAccounts | Select-Object -Unique
$siteCollectionOwners = $siteCollectionOwners | Select-Object -Unique
# Check for the existence of object cache accounts and other ones for which we don't need to specify passwords
$accountsToCheck = @($xmlInput.Configuration.Farm.ObjectCacheAccounts.SuperUser,$xmlInput.Configuration.Farm.ObjectCacheAccounts.SuperReader)+$appPoolAccounts+$siteCollectionOwners | Select-Object -Unique
foreach ($account in $accountsToCheck)
{
$domain,$accountName = $account -split "\\"
Write-Host -ForegroundColor White " - Account `"$account`"..." -NoNewline
if (!(userExists $accountName))
{
Write-Host -BackgroundColor Red -ForegroundColor Black "Invalid!"
$acctInvalid = $true
}
else
{
Write-Host -ForegroundColor Black -BackgroundColor Green "Verified."
}
}
If ($acctInvalid) {Throw " - At least one set of credentials is invalid.`n - Check usernames and passwords in each place they are used."}
WriteLine
}
#endregion
#region Unblock Files / Trust Source Path & Remove IE Enhanced Security
Function UnblockFiles ($path)
{
# Ensure that if we're running from a UNC path, the host portion is added to the Local Intranet zone so we don't get the "Open File - Security Warning"
If ($env:dp0 -like "\\*")
{
WriteLine
if (Get-Command -Name "Unblock-File" -ErrorAction SilentlyContinue)
{
Write-Host -ForegroundColor White " - Unblocking executable files in $path to prevent security prompts..." -NoNewline
# Leverage the Unblock-File cmdlet, if available to prevent security warnings when working with language packs, CUs etc.
Get-ChildItem -Path $path -Recurse | Where-Object {($_.Name -like "*.exe") -or ($_.Name -like "*.ms*") -or ($_.Name -like "*.zip") -or ($_.Name -like "*.cab")} | Unblock-File -Confirm:$false -ErrorAction SilentlyContinue
Write-Host -ForegroundColor White "Done."
}
$safeHost = ($env:dp0 -split "\\")[2]
Write-Host -ForegroundColor White " - Adding location `"$safeHost`" to local Intranet security zone to prevent security prompts..." -NoNewline
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains" -Name $safeHost -ItemType Leaf -Force | Out-Null
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\$safeHost" -Name "file" -value "1" -PropertyType dword -Force | Out-Null
Write-Host -ForegroundColor White "Done."
WriteLine
}
}
Function RemoveIEEnhancedSecurity ([xml]$xmlInput)
{
WriteLine
If ($xmlInput.Configuration.Install.Disable.IEEnhancedSecurity -eq "True")
{
Write-Host -ForegroundColor White " - Disabling IE Enhanced Security..."
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0 -ErrorAction SilentlyContinue
Rundll32 iesetup.dll, IEHardenLMSettings,1,True
Rundll32 iesetup.dll, IEHardenUser,1,True
Rundll32 iesetup.dll, IEHardenAdmin,1,True
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -ErrorAction SilentlyContinue)
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
}
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -ErrorAction SilentlyContinue)
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
}
#This doesn't always exist
Remove-ItemProperty "HKCU:\SOFTWARE\Microsoft\Internet Explorer\Main" "First Home Page" -ErrorAction SilentlyContinue
}
Else
{
Write-Host -ForegroundColor White " - Not configured to change IE Enhanced Security."
}
WriteLine
}
#endregion
#region Disable Certificate Revocation List checks
Function DisableCRLCheck ([xml]$xmlInput)
{
WriteLine
If ($xmlInput.Configuration.Install.Disable.CertificateRevocationListCheck -eq "True")
{
Write-Host -ForegroundColor White " - Disabling Certificate Revocation List (CRL) check..."
Write-Host -ForegroundColor White " - Registry..."
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -PropertyType DWord -Value 146944 -Force | Out-Null
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -PropertyType DWord -Value 146944 -Force | Out-Null
Write-Host -ForegroundColor White " - Machine.config files..."
[array]$frameworkVersions = "v2.0.50727","v4.0.30319" # For .Net 2.0 and .Net 4.0
ForEach($bitsize in ("","64"))
{
foreach ($frameworkVersion in $frameworkVersions)
{
# Added a check below for $xml because on Windows Server 2012 machines, the path to $xml doesn't exist until the .Net Framework is installed, so the steps below were failing
$xml = [xml](Get-Content "$env:windir\Microsoft.NET\Framework$bitsize\$frameworkVersion\CONFIG\Machine.config" -ErrorAction SilentlyContinue)
if ($xml)
{
if ($bitsize -eq "64") {Write-Host -ForegroundColor White " - $frameworkVersion..." -NoNewline}
If (!$xml.DocumentElement.SelectSingleNode("runtime"))
{
$runtime = $xml.CreateElement("runtime")
$xml.DocumentElement.AppendChild($runtime) | Out-Null
}
If (!$xml.DocumentElement.SelectSingleNode("runtime/generatePublisherEvidence"))
{
$gpe = $xml.CreateElement("generatePublisherEvidence")
$xml.DocumentElement.SelectSingleNode("runtime").AppendChild($gpe) | Out-Null
}
$xml.DocumentElement.SelectSingleNode("runtime/generatePublisherEvidence").SetAttribute("enabled","false") | Out-Null
$xml.Save("$env:windir\Microsoft.NET\Framework$bitsize\$frameworkVersion\CONFIG\Machine.config")
if ($bitsize -eq "64") {Write-Host -ForegroundColor White "OK."}
}
else
{
if ($bitsize -eq "") {$bitsize = "32"}
Write-Warning "$bitsize-bit machine.config not found - could not disable CRL check."
}
}
}
Write-Host -ForegroundColor White " - Done."
}
Else
{
Write-Host -ForegroundColor White " - Not changing CRL check behavior."
}
WriteLine
}
#endregion
#region Start logging to user's desktop
Function StartTracing ($server)
{
If (!$isTracing)
{
# Look for an existing log file start time in the registry so we can re-use the same log file
$regKey = Get-Item -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -ErrorAction SilentlyContinue
If ($regKey) {$script:Logtime = $regkey.GetValue("LogTime")}
If ([string]::IsNullOrEmpty($logtime)) {$script:Logtime = Get-Date -Format yyyy-MM-dd_h-mm}
If ($server) {$script:LogFile = "$env:USERPROFILE\Desktop\AutoSPInstaller-$server-$script:Logtime.log"}
else {$script:LogFile = "$env:USERPROFILE\Desktop\AutoSPInstaller-$script:Logtime.log"}
Start-Transcript -Path $logFile -Append -Force
If ($?) {$script:isTracing = $true}
}
}
#endregion
#region Check Input File
Function CheckInput ($inputFile)
{
# Check that the config file exists.
If (-not $(Test-Path -Path $inputFile -Type Leaf))
{
Write-Error -message (" - Input file '" + $inputFile + "' does not exist.")
}
}
#endregion
#region Check For or Create Config Files
Function CheckConfigFiles ([xml]$xmlInput)
{
#region SharePoint config file
if (Test-Path -Path (Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.Install.ConfigFile)))
{
# Just use the existing config file we found
$script:configFile = Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.Install.ConfigFile)
Write-Host -ForegroundColor White " - Using existing config file:`n - $configFile"
}
else
{
$spYear = $xmlInput.Configuration.Install.SPVersion
$spVer = Get-MajorVersionNumber $spYear
# Write out a new config file based on defaults and the values provided in $inputFile
$pidKey = $xmlInput.Configuration.Install.PIDKey
# Do a rudimentary check on the presence and format of the product key
if ($pidKey -notlike "?????-?????-?????-?????-?????")
{
throw " - The Product ID (PIDKey) is missing or badly formatted.`n - Check the value of <PIDKey> in `"$(Split-Path -Path $inputFile -Leaf)`" and try again."
}
$officeServerPremium = $xmlInput.Configuration.Install.SKU -replace "Enterprise","1" -replace "Standard","0"
$installDir = $xmlInput.Configuration.Install.InstallDir
# Set $installDir to the default value if it's not specified in $xmlInput
if ([string]::IsNullOrEmpty($installDir)) {$installDir = "%PROGRAMFILES%\Microsoft Office Servers\"}
$dataDir = $xmlInput.Configuration.Install.DataDir
# Set $dataDir to the default value if it's not specified in $xmlInput
if ([string]::IsNullOrEmpty($dataDir)) {$dataDir = "%PROGRAMFILES%\Microsoft Office Servers\$spVer.0\Data"}
$dataDir = $dataDir.TrimEnd("\")
$xmlConfig = @"
<Configuration>
<Package Id="sts">
<Setting Id="LAUNCHEDFROMSETUPSTS" Value="Yes"/>
</Package>
<Package Id="spswfe">
<Setting Id="SETUPCALLED" Value="1"/>
<Setting Id="OFFICESERVERPREMIUM" Value="$officeServerPremium" />
</Package>
<ARP ARPCOMMENTS="Installed with AutoSPInstaller (http://autospinstaller.com)" ARPCONTACT="brian@autospinstaller.com" />
<Logging Type="verbose" Path="%temp%" Template="SharePoint Server Setup(*).log"/>
<Display Level="basic" CompletionNotice="No" AcceptEula="Yes"/>
<INSTALLLOCATION Value="$installDir"/>
<DATADIR Value="$dataDir"/>
<PIDKEY Value="$pidKey"/>
<Setting Id="SERVERROLE" Value="APPLICATION"/>
<Setting Id="USINGUIINSTALLMODE" Value="1"/>
<Setting Id="SETUPTYPE" Value="CLEAN_INSTALL"/>
<Setting Id="SETUP_REBOOT" Value="Never"/>
<Setting Id="AllowWindowsClientInstall" Value="True"/>
</Configuration>
"@
$script:configFile = Join-Path -Path (Get-Item $env:TEMP).FullName -ChildPath $($xmlInput.Configuration.Install.ConfigFile)
Write-Host -ForegroundColor White " - Writing $($xmlInput.Configuration.Install.ConfigFile) to $((Get-Item $env:TEMP).FullName)..."
Set-Content -Path "$configFile" -Force -Value $xmlConfig
}
#endregion
#region OWA config file
if ($xmlInput.Configuration.OfficeWebApps.Install -eq $true)
{
if (Test-Path -Path (Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.OfficeWebApps.ConfigFile)))
{
# Just use the existing config file we found
$script:configFileOWA = Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.OfficeWebApps.ConfigFile)
Write-Host -ForegroundColor White " - Using existing OWA config file:`n - $configFileOWA"
}
else
{
# Write out a new config file based on defaults and the values provided in $inputFile
$pidKeyOWA = $xmlInput.Configuration.OfficeWebApps.PIDKeyOWA
# Do a rudimentary check on the presence and format of the product key
if ($pidKeyOWA -notlike "?????-?????-?????-?????-?????")
{
throw " - The OWA Product ID (PIDKey) is missing or badly formatted.`n - Check the value of <PIDKeyOWA> in `"$(Split-Path -Path $inputFile -Leaf)`" and try again."
}
$xmlConfigOWA = @"
<Configuration>
<Package Id="sts">
<Setting Id="LAUNCHEDFROMSETUPSTS" Value="Yes"/>
</Package>
<ARP ARPCOMMENTS="Installed with AutoSPInstaller (http://autospinstaller.com)" ARPCONTACT="brian@autospinstaller.com" />
<Logging Type="verbose" Path="%temp%" Template="Wac Server Setup(*).log"/>
<Display Level="basic" CompletionNotice="no" />
<Setting Id="SERVERROLE" Value="APPLICATION"/>
<PIDKEY Value="$pidKeyOWA"/>
<Setting Id="USINGUIINSTALLMODE" Value="1"/>
<Setting Id="SETUPTYPE" Value="CLEAN_INSTALL"/>
<Setting Id="SETUP_REBOOT" Value="Never"/>
<Setting Id="AllowWindowsClientInstall" Value="True"/>
</Configuration>
"@
$script:configFileOWA = Join-Path -Path (Get-Item $env:TEMP).FullName -ChildPath $($xmlInput.Configuration.OfficeWebApps.ConfigFile)
Write-Host -ForegroundColor White " - Writing $($xmlInput.Configuration.OfficeWebApps.ConfigFile) to $((Get-Item $env:TEMP).FullName)..."
Set-Content -Path "$configFileOWA" -Force -Value $xmlConfigOWA
}
}
#endregion
#region Project Server config file
if ($xmlInput.Configuration.ProjectServer.Install -eq $true)
{
$pidKeyProjectServer = $xmlInput.Configuration.ProjectServer.PIDKeyProjectServer
# Do a rudimentary check on the presence and format of the product key
if ($pidKeyProjectServer -notlike "?????-?????-?????-?????-?????")
{
throw " - The Project Server Product ID (PIDKey) is missing or badly formatted.`n - Check the value of <PIDKeyProjectServer> in `"$(Split-Path -Path $inputFile -Leaf)`" and try again."
}
if ($spYear -eq 2013) # We only need this config file for Project Server 2013 / SP2013
{
if (Test-Path -Path (Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.ProjectServer.ConfigFile)))
{
# Just use the existing config file we found
$script:configFileProjectServer = Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.ProjectServer.ConfigFile)
Write-Host -ForegroundColor White " - Using existing ProjectServer config file:`n - $configFileProjectServer"
}
else
{
# Write out a new config file based on defaults and the values provided in $inputFile
$xmlConfigProjectServer = @"
<Configuration>
<Package Id="sts">
<Setting Id="LAUNCHEDFROMSETUPSTS" Value="Yes"/>
</Package>
<Package Id="PJSRVWFE">
<Setting Id="PSERVER" Value="1"/>
</Package>
<ARP ARPCOMMENTS="Installed with AutoSPInstaller (http://autospinstaller.com)" ARPCONTACT="brian@autospinstaller.com" />
<Logging Type="verbose" Path="%temp%" Template="Project Server Setup(*).log"/>
<Display Level="basic" CompletionNotice="No" AcceptEula="Yes"/>
<Setting Id="SERVERROLE" Value="APPLICATION"/>
<PIDKEY Value="$pidKeyProjectServer"/>
<Setting Id="USINGUIINSTALLMODE" Value="1"/>
<Setting Id="SETUPTYPE" Value="CLEAN_INSTALL"/>
<Setting Id="SETUP_REBOOT" Value="Never"/>
<Setting Id="AllowWindowsClientInstall" Value="True"/>
</Configuration>
"@
$script:configFileProjectServer = Join-Path -Path (Get-Item $env:TEMP).FullName -ChildPath $($xmlInput.Configuration.ProjectServer.ConfigFile)
Write-Host -ForegroundColor White " - Writing $($xmlInput.Configuration.ProjectServer.ConfigFile) to $((Get-Item $env:TEMP).FullName)..."
Set-Content -Path "$configFileProjectServer" -Force -Value $xmlConfigProjectServer
}
}
}
#endregion
#region ForeFront answer file
if (ShouldIProvision $xmlInput.Configuration.ForeFront -eq $true)
{
if (Test-Path -Path (Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.ForeFront.ConfigFile)))
{
# Just use the existing answer file we found
$script:configFileForeFront = Join-Path -Path $env:dp0 -ChildPath $($xmlInput.Configuration.ForeFront.ConfigFile)
Write-Host -ForegroundColor White " - Using existing ForeFront answer file:`n - $configFileForeFront"
}
else
{
$farmAcct = $xmlInput.Configuration.Farm.Account.Username
$farmAcctPWD = $xmlInput.Configuration.Farm.Account.Password
# Write out a new answer file based on defaults and the values provided in $inputFile
$xmlConfigForeFront = @"
<?xml version="1.0" encoding="utf-8"?>
<FSSAnswerFile>
<AcceptLicense>true</AcceptLicense>
<AcceptRestart>true</AcceptRestart>
<AcceptReplacePreviousVS>true</AcceptReplacePreviousVS>
<InstallType>Full</InstallType>
<Folders>
<!--Leave these empty to use the default values-->
<ProgramFolder></ProgramFolder>
<DataFolder></DataFolder>
</Folders>
<ProxyInformation>
<UseProxy>false</UseProxy>
<ServerName></ServerName>
<Port>80</Port>
<UserName></UserName>
<Password></Password>
</ProxyInformation>
<SharePointInformation>
<UserName>$farmAcct</UserName>
<Password>$farmAcctPWD</Password>
</SharePointInformation>
<EnableAntiSpamNow>false</EnableAntiSpamNow>
<EnableCustomerExperienceImprovementProgram>false</EnableCustomerExperienceImprovementProgram>
</FSSAnswerFile>
"@
$script:configFileForeFront = Join-Path -Path (Get-Item $env:TEMP).FullName -ChildPath $($xmlInput.Configuration.ForeFront.ConfigFile)
Write-Host -ForegroundColor White " - Writing $($xmlInput.Configuration.ForeFront.ConfigFile) to $((Get-Item $env:TEMP).FullName)..."
Set-Content -Path "$configFileForeFront" -Force -Value $xmlConfigForeFront
}
}
#endregion
}
#endregion
#region Check Installation Account
# ===================================================================================
# Func: CheckInstallAccount
# Desc: Check the install account and
# ===================================================================================
Function CheckInstallAccount ([xml]$xmlInput)
{
# Check if we are running under Farm Account credentials
$farmAcct = $xmlInput.Configuration.Farm.Account.Username
If ($env:USERDOMAIN+"\"+$env:USERNAME -eq $farmAcct)
{
Write-Host -ForegroundColor Yellow " - WARNING: Running install using Farm Account: $farmAcct"
}
}
#endregion
#region Disable Loopback Check and Services
# ===================================================================================
# Func: DisableLoopbackCheck
# Desc: Disable Loopback Check
# ===================================================================================
Function DisableLoopbackCheck ([xml]$xmlInput)
{
# Disable the Loopback Check on stand alone demo servers.
# This setting usually kicks out a 401 error when you try to navigate to sites that resolve to a loopback address e.g. 127.0.0.1
If ($xmlInput.Configuration.Install.Disable.LoopbackCheck -eq $true)
{
WriteLine
Write-Host -ForegroundColor White " - Disabling Loopback Check..."
$lsaPath = "HKLM:\System\CurrentControlSet\Control\Lsa"
$lsaPathValue = Get-ItemProperty -path $lsaPath
If (-not ($lsaPathValue.DisableLoopbackCheck -eq "1"))
{
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword -Force | Out-Null
}
WriteLine
}
}
# ===================================================================================
# Func: DisableServices
# Desc: Disable Unused Services or set status to Manual
# ===================================================================================
Function DisableServices ([xml]$xmlInput)
{
If ($xmlInput.Configuration.Install.Disable.UnusedServices -eq $true)
{
WriteLine
Write-Host -ForegroundColor White " - Setting services Spooler, AudioSrv and TabletInputService to Manual..."
$servicesToSetManual = "Spooler","AudioSrv","TabletInputService"
ForEach ($svcName in $servicesToSetManual)
{
$svc = get-wmiobject win32_service | where-object {$_.Name -eq $svcName}
$svcStartMode = $svc.StartMode
$svcState = $svc.State
If (($svcState -eq "Running") -and ($svcStartMode -eq "Auto"))
{
Stop-Service -Name $svcName
Set-Service -name $svcName -StartupType Manual
Write-Host -ForegroundColor White " - Service $svcName is now set to Manual start"
}
Else
{
Write-Host -ForegroundColor White " - $svcName is already stopped and set Manual, no action required."
}
}
Write-Host -ForegroundColor White " - Setting unused services WerSvc to Disabled..."
$servicesToDisable = "WerSvc"
ForEach ($svcName in $servicesToDisable)
{
$svc = get-wmiobject win32_service | where-object {$_.Name -eq $svcName}
$svcStartMode = $svc.StartMode
$svcState = $svc.State
If (($svcState -eq "Running") -and (($svcStartMode -eq "Auto") -or ($svcStartMode -eq "Manual")))
{
Stop-Service -Name $svcName
Set-Service -name $svcName -StartupType Disabled
Write-Host -ForegroundColor White " - Service $svcName is now stopped and disabled."
}
Else
{
Write-Host -ForegroundColor White " - $svcName is already stopped and disabled, no action required."
}
}
Write-Host -ForegroundColor White " - Finished disabling services."
WriteLine
}
}
#endregion
#region Install Prerequisites
# ===================================================================================
# Func: InstallPrerequisites
# Desc: If SharePoint is not already installed install the Prerequisites
# ===================================================================================
Function InstallPrerequisites ([xml]$xmlInput)
{
$spYear = $xmlInput.Configuration.Install.SPVersion
WriteLine
# Remove any lingering post-reboot registry values first
Remove-ItemProperty -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -Name "RestartRequired" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -Name "CancelRemoteInstall" -ErrorAction SilentlyContinue
# Check for whether UAC was previously enabled and should therefore be re-enabled after an automatic restart
$regKey = Get-Item -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -ErrorAction SilentlyContinue
If ($regKey) {$UACWasEnabled = $regkey.GetValue("UACWasEnabled")}
If ($UACWasEnabled -eq 1) {Set-UserAccountControl 1}
# Now, remove the lingering registry UAC flag
Remove-ItemProperty -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -Name "UACWasEnabled" -ErrorAction SilentlyContinue
$spInstalled = Get-SharePointInstall
If ($spInstalled)
{
Write-Host -ForegroundColor White " - SharePoint $spYear prerequisites appear be already installed - skipping install."
}
Else
{
Write-Host -ForegroundColor White " - Installing Prerequisite Software:"
If ((Get-WmiObject Win32_OperatingSystem).Version -eq "6.1.7601") # Win2008 R2 SP1
{
# Due to the SharePoint 2010 issue described in http://support.microsoft.com/kb/2581903 (related to installing the KB976462 hotfix)
# (and simply to speed things up for SharePoint 2013) we install the .Net 3.5.1 features prior to attempting the PrerequisiteInstaller on Win2008 R2 SP1
Write-Host -ForegroundColor White " - .Net Framework 3.5.1..." -NoNewline
# Get the current progress preference
$pref = $ProgressPreference
# Hide the progress bar since it tends to not disappear
$ProgressPreference = "SilentlyContinue"
Import-Module ServerManager
If (!(Get-WindowsFeature -Name NET-Framework).Installed)
{
Add-WindowsFeature -Name NET-Framework | Out-Null
Write-Host -ForegroundColor Green "Done."
}
else {Write-Host -ForegroundColor White "Already installed."}
# Restore progress preference
$ProgressPreference = $pref
}
Try
{
# Detect if we're installing SP2010 on Windows Server 2012 (R2)
if ((Get-WmiObject Win32_OperatingSystem).Version -like "6.2*")
{
$osName = "Windows Server 2012"
$win2012 = $true
$prereqInstallerRequiredBuild = "7009" # i.e. minimum required version of PrerequisiteInstaller.exe for Windows Server 2012 is 14.0.7009.1000
}
elseif ((Get-WmiObject Win32_OperatingSystem).Version -like "6.3*")
{
$osName = "Windows Server 2012 R2"
$win2012 = $true
$prereqInstallerRequiredBuild = "7104" # i.e. minimum required version of PrerequisiteInstaller.exe for Windows Server 2012 R2 is 14.0.7104.5000
}
else {$win2012 = $false}
if ($win2012 -and ($spYear -eq 2010))
{
Write-Host -ForegroundColor White " - Checking for required version of PrerequisiteInstaller.exe..." -NoNewline
$prereqInstallerVer = (Get-Command $env:SPbits\PrerequisiteInstaller.exe).FileVersionInfo.ProductVersion
$null,$null,$prereqInstallerBuild,$null = $prereqInstallerVer -split "\."
# Check that the version of PrerequisiteInstaller.exe included in the MS-provided SharePoint 2010 SP2-integrated package meets the minimum required version for the detected OS
if ($prereqInstallerBuild -lt $prereqInstallerRequiredBuild)
{
Write-Host -ForegroundColor White "."
Throw " - SharePoint 2010 is officially unsupported on $osName without an updated set of SP2-integrated binaries - see http://support.microsoft.com/kb/2724471"
}
else {Write-Host -BackgroundColor Green -ForegroundColor Black "OK."}
}
# Install using PrerequisiteInstaller as usual
If ($xmlInput.Configuration.Install.OfflineInstall -eq $true) # Install all prerequisites from local folder
{
# Try to pre-install .Net Framework 3.5.1 on Windows Server 2012, 2012 R2 or 2016
if ((Get-WmiObject Win32_OperatingSystem).Version -like "6.2*" -or (Get-WmiObject Win32_OperatingSystem).Version -like "6.3*" -or (Get-WmiObject Win32_OperatingSystem).Version -like "6.4*" -or (Get-WmiObject Win32_OperatingSystem).Version -like "10.0*")
{
if (Test-Path -Path "$env:SPbits\PrerequisiteInstallerFiles\sxs")
{
Write-Host -ForegroundColor White " - .Net Framework 3.5.1 from `"$env:SPbits\PrerequisiteInstallerFiles\sxs`"..." -NoNewline
# Get the current progress preference
$pref = $ProgressPreference
# Hide the progress bar since it tends to not disappear
$ProgressPreference = "SilentlyContinue"
Import-Module ServerManager
if (!(Get-WindowsFeature -Name NET-Framework-Core).Installed)
{
Start-Process -FilePath DISM.exe -ArgumentList "/Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:`"$env:SPbits\PrerequisiteInstallerFiles\sxs`"" -NoNewWindow -Wait
##Install-WindowsFeature NET-Framework-Core -Source "$env:SPbits\PrerequisiteInstallerFiles\sxs" | Out-Null
Write-Host -ForegroundColor Green "Done."
}
else {Write-Host -ForegroundColor White "Already installed."}
# Restore progress preference
$ProgressPreference = $pref
}
else {Write-Host -ForegroundColor White " - Could not locate source for .Net Framework 3.5.1`n - The PrerequisiteInstaller will attempt to download it."}
}
if ($spYear -eq 2010) # SP2010
{
Write-Host -ForegroundColor White " - SQL Native Client..."
# Install SQL native client before running pre-requisite installer as newest versions require an IACCEPTSQLNCLILICENSETERMS=YES argument
Start-Process "$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi" -Wait -ArgumentList "/passive /norestart IACCEPTSQLNCLILICENSETERMS=YES"
Write-Host -ForegroundColor Cyan " - Running Prerequisite Installer (offline mode)..." -NoNewline
$startTime = Get-Date
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended `
/SQLNCli:`"$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi`" `
/ChartControl:`"$env:SPbits\PrerequisiteInstallerFiles\MSChart.exe`" `
/NETFX35SP1:`"$env:SPbits\PrerequisiteInstallerFiles\dotnetfx35.exe`" `
/PowerShell:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.0-KB968930-x64.msu`" `
/KB976394:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.0-KB976394-x64.msu`" `
/KB976462:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB976462-v2-x64.msu`" `
/IDFX:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.0-KB974405-x64.msu`" `
/IDFXR2:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu`" `
/Sync:`"$env:SPbits\PrerequisiteInstallerFiles\Synchronization.msi`" `
/FilterPack:`"$env:SPbits\PrerequisiteInstallerFiles\FilterPack\FilterPack.msi`" `
/ADOMD:`"$env:SPbits\PrerequisiteInstallerFiles\SQLSERVER2008_ASADOMD10.msi`" `
/ReportingServices:`"$env:SPbits\PrerequisiteInstallerFiles\rsSharePoint.msi`" `
/Speech:`"$env:SPbits\PrerequisiteInstallerFiles\SpeechPlatformRuntime.msi`" `
/SpeechLPK:`"$env:SPbits\PrerequisiteInstallerFiles\MSSpeech_SR_en-US_TELE.msi`""
If (-not $?) {Throw}
}
elseif ($spYear -eq 2013) #SP2013
{
Write-Host -ForegroundColor Cyan " - Running Prerequisite Installer (offline mode)..." -NoNewline
$startTime = Get-Date
if (CheckFor2013SP1 -xmlInput $xmlInput) # Include WCFDataServices56 as required by updated SP1 prerequisiteinstaller.exe
{
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended `
/SQLNCli:`"$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi`" `
/PowerShell:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB2506143-x64.msu`" `
/NETFX:`"$env:SPbits\PrerequisiteInstallerFiles\dotNetFx45_Full_x86_x64.exe`" `
/IDFX:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu`" `
/IDFX11:`"$env:SPbits\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi`" `
/Sync:`"$env:SPbits\PrerequisiteInstallerFiles\Synchronization.msi`" `
/AppFabric:`"$env:SPbits\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe`" `
/KB2671763:`"$env:SPbits\PrerequisiteInstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe`" `
/MSIPCClient:`"$env:SPbits\PrerequisiteInstallerFiles\setup_msipc_x64.msi`" `
/WCFDataServices:`"$env:SPbits\PrerequisiteInstallerFiles\WcfDataServices.exe`" `
/WCFDataServices56:`"$env:SPbits\PrerequisiteInstallerFiles\WcfDataServices56.exe`""
If (-not $?) {Throw}
}
else # Just install the pre-SP1 set of prerequisites
{
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended `
/SQLNCli:`"$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi`" `
/PowerShell:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB2506143-x64.msu`" `
/NETFX:`"$env:SPbits\PrerequisiteInstallerFiles\dotNetFx45_Full_x86_x64.exe`" `
/IDFX:`"$env:SPbits\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu`" `
/IDFX11:`"$env:SPbits\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi`" `
/Sync:`"$env:SPbits\PrerequisiteInstallerFiles\Synchronization.msi`" `
/AppFabric:`"$env:SPbits\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe`" `
/KB2671763:`"$env:SPbits\PrerequisiteInstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe`" `
/MSIPCClient:`"$env:SPbits\PrerequisiteInstallerFiles\setup_msipc_x64.msi`" `
/WCFDataServices:`"$env:SPbits\PrerequisiteInstallerFiles\WcfDataServices.exe`""
If (-not $?) {Throw}
}
}
elseif ($spYear -eq "2016") #SP2016
{
Write-Host -ForegroundColor Cyan " - Running Prerequisite Installer (offline mode)..." -NoNewline
$startTime = Get-Date
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended `
/SQLNCli:`"$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi`" `
/Sync:`"$env:SPbits\PrerequisiteInstallerFiles\Synchronization.msi`" `
/AppFabric:`"$env:SPbits\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe`" `
/IDFX11:`"$env:SPbits\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi`" `
/MSIPCClient:`"$env:SPbits\PrerequisiteInstallerFiles\setup_msipc_x64.exe`" `
/KB3092423:`"$env:SPbits\PrerequisiteInstallerFiles\AppFabric-KB3092423-x64-ENU.exe`" `
/WCFDataServices56:`"$env:SPbits\PrerequisiteInstallerFiles\WcfDataServices.exe`" `
/ODBC:`"$env:SPbits\PrerequisiteInstallerFiles\msodbcsql.msi`" `
/DotNetFx:`"$env:SPbits\PrerequisiteInstallerFiles\NDP46-KB3045557-x86-x64-AllOS-ENU.exe`" `
/MSVCRT11:`"$env:SPbits\PrerequisiteInstallerFiles\vcredist_x64.exe`" `
/MSVCRT14:`"$env:SPbits\PrerequisiteInstallerFiles\vc_redist.x64.exe`""
If (-not $?) {Throw}
}
elseif ($spYear -eq "2019") #SP2019
{
Write-Host -ForegroundColor Cyan " - Running Prerequisite Installer (offline mode)..." -NoNewline
$startTime = Get-Date
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended `
/SQLNCli:`"$env:SPbits\PrerequisiteInstallerFiles\sqlncli.msi`" `
/Sync:`"$env:SPbits\PrerequisiteInstallerFiles\Synchronization.msi`" `
/AppFabric:`"$env:SPbits\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe`" `
/IDFX11:`"$env:SPbits\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi`" `
/MSIPCClient:`"$env:SPbits\PrerequisiteInstallerFiles\setup_msipc_x64.exe`" `
/KB3092423:`"$env:SPbits\PrerequisiteInstallerFiles\AppFabric-KB3092423-x64-ENU.exe`" `
/WCFDataServices56:`"$env:SPbits\PrerequisiteInstallerFiles\WcfDataServices.exe`" `
/DotNet472:`"$env:SPbits\PrerequisiteInstallerFiles\NDP472-KB4054530-x86-x64-AllOS-ENU.exe`" `
/MSVCRT11:`"$env:SPbits\PrerequisiteInstallerFiles\vcredist_x64.exe`" `
/MSVCRT141:`"$env:SPbits\PrerequisiteInstallerFiles\vc_redist.x64.exe`" `
"
If (-not $?) {Throw}
}
}
else # Regular prerequisite install - download required files
{
Write-Host -ForegroundColor Cyan " - Running Prerequisite Installer (online mode)..." -NoNewline
$startTime = Get-Date
Start-Process "$env:SPbits\PrerequisiteInstaller.exe" -ArgumentList "/unattended" -WindowStyle Minimized
If (-not $?) {Throw}
}
Show-Progress -Process PrerequisiteInstaller -Color Cyan -Interval 5
$delta,$null = (New-TimeSpan -Start $startTime -End (Get-Date)).ToString() -split "\."
Write-Host -ForegroundColor White " - Prerequisite Installer completed in $delta."
If ($spYear -eq 2013) # SP2013
{
# Install the "missing prerequisites" for SP2013 per http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=349
# Expand hotfix executable to $env:SPbits\PrerequisiteInstallerFiles\
if ((Get-WmiObject Win32_OperatingSystem).Version -eq "6.1.7601") # Win2008 R2 SP1
{
$missingHotfixes = @{"Windows6.1-KB2554876-v2-x64.msu" = "http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix368051/7600/free/433385_intl_x64_zip.exe";
"Windows6.1-KB2708075-x64.msu" = "http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix402568/7600/free/447698_intl_x64_zip.exe";
"Windows6.1-KB2472264-v3-x64.msu" = "http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix354400/7600/free/427087_intl_x64_zip.exe";
"Windows6.1-KB2567680-x64.msu" = "http://download.microsoft.com/download/C/D/A/CDAF5DD8-3B9A-4F8D-A48F-BEFE53C5B249/Windows6.1-KB2567680-x64.msu";
"NDP45-KB2759112-x64.exe" = "http://download.microsoft.com/download/5/6/3/5631B753-A009-48AF-826C-2D2C29B94172/NDP45-KB2759112-x64.exe"}
}
elseif ((Get-WmiObject Win32_OperatingSystem).Version -like "6.2*") # Win2012
{
$missingHotfixes = @{"Windows8-RT-KB2765317-x64.msu" = "http://download.microsoft.com/download/0/2/E/02E9E569-5462-48EB-AF57-8DCCF852E6F4/Windows8-RT-KB2765317-x64.msu"}
}
else {} # Reserved for Win2012 R2
if ($missingHotfixes.Count -ge 1)
{
Write-Host -ForegroundColor White " - SharePoint 2013 `"missing hotfix`" prerequisites..."
$hotfixLocation = $env:SPbits+"\PrerequisiteInstallerFiles"
}
ForEach ($hotfixPatch in $missingHotfixes.Keys)
{
$hotfixKB = $hotfixPatch.Split('-') | Where-Object {$_ -like "KB*"}
# Check if the hotfix is already installed
Write-Host -ForegroundColor White " - Checking for $hotfixKB..." -NoNewline
If (!(Get-HotFix -Id $hotfixKB -ErrorAction SilentlyContinue))
{
Write-Host -ForegroundColor White "Missing; attempting to install..."
$hotfixUrl = $missingHotfixes.$hotfixPatch
$hotfixFile = $hotfixUrl.Split('/')[-1]
$hotfixFileZip = $hotfixFile+".zip"
$hotfixZipPath = Join-Path -Path $hotfixLocation -ChildPath $hotfixFileZip
# Check if the .msu/.exe file is already present
If (Test-Path "$hotfixLocation\$hotfixPatch")
{
Write-Host -ForegroundColor White " - Hotfix file `"$hotfixPatch`" found."
}
Else
{
# Check if the downloaded package exists with a .zip extension
If (!([string]::IsNullOrEmpty($hotfixFileZip)) -and (Test-Path "$hotfixLocation\$hotfixFileZip"))
{
Write-Host -ForegroundColor White " - File $hotfixFile (zip) found."
}
Else
{
# Check if the downloaded package exists
If (Test-Path "$hotfixLocation\$hotfixFile")
{
Write-Host -ForegroundColor White " - File $hotfixFile found."
}
Else # Go ahead and download the missing package
{
Try
{
# Begin download
Write-Host -ForegroundColor White " - Hotfix $hotfixPatch not found in $env:SPbits\PrerequisiteInstallerFiles"
Write-Host -ForegroundColor White " - Attempting to download..." -NoNewline
Import-Module BitsTransfer | Out-Null
Start-BitsTransfer -Source $hotfixUrl -Destination "$hotfixLocation\$hotfixFile" -DisplayName "Downloading `'$hotfixFile`' to $hotfixLocation" -Priority Foreground -Description "From $hotfixUrl..." -ErrorVariable err
if ($err) {Write-Host "."; Throw " - Could not download from $hotfixUrl!"}
Write-Host -ForegroundColor White "Done!"
}
Catch
{
Write-Warning " - An error occurred attempting to download `"$hotfixFile`"."
break
}
}
if ($hotfixFile -like "*zip.exe") # The hotfix is probably a self-extracting exe
{
# Give the file a .zip extension so we can work with it like a compressed folder
Write-Host -ForegroundColor White " - Renaming $hotfixFile to $hotfixFileZip..."
Rename-Item -Path "$hotfixLocation\$hotfixFile" -NewName $hotfixFileZip -Force -ErrorAction SilentlyContinue
}
}
If (Test-Path "$hotfixLocation\$hotfixFileZip") # The zipped hotfix exists, ands needs to be extracted
{
Write-Host -ForegroundColor White " - Extracting `"$hotfixPatch`" from `"$hotfixFile`"..." -NoNewline
$shell = New-Object -ComObject Shell.Application
$hotfixFileZipNs = $shell.Namespace($hotfixZipPath)
$hotfixLocationNs = $shell.Namespace($hotfixLocation)
$hotfixLocationNs.Copyhere($hotfixFileZipNs.items())
Write-Host -ForegroundColor Green "Done."
}
}
# Install the hotfix
$extractedHotfixPath = Join-Path -Path $hotfixLocation -ChildPath $hotfixPatch
Write-Host -ForegroundColor White " - Installing hotfix $hotfixPatch..." -NoNewline
if ($hotfixPatch -like "*.msu") # Treat as a Windows Update patch
{
Start-Process -FilePath "wusa.exe" -ArgumentList "`"$extractedHotfixPath`" /quiet /norestart" -Wait -NoNewWindow
}
else # Treat as an executable (.exe) patch
{
Start-Process -FilePath "$extractedHotfixPath" -ArgumentList "/passive /norestart" -Wait -NoNewWindow
}
Write-Host -ForegroundColor Green "Done."
}
Else {Write-Host -ForegroundColor White "Already installed."}
}
}
}
Catch
{
Write-Host -ForegroundColor Cyan "."
Write-Host -ForegroundColor Red " - Error: $_ $LASTEXITCODE"
If ($LASTEXITCODE -eq "1") {Throw " - Another instance of this application is already running"}
ElseIf ($LASTEXITCODE -eq "2") {Throw " - Invalid command line parameter(s)"}
ElseIf ($LASTEXITCODE -eq "1001") {Throw " - A pending restart blocks installation"}
ElseIf ($LASTEXITCODE -eq "3010") {Throw " - A restart is needed"}
ElseIf ($LASTEXITCODE -eq "-2145124329") {Write-Host -ForegroundColor White " - A known issue occurred installing one of the prerequisites"; InstallPreRequisites ([xml]$xmlInput)}
Else {Throw " - An unknown error occurred installing prerequisites"}
}
# Parsing most recent PreRequisiteInstaller log for errors or restart requirements, since $LASTEXITCODE doesn't seem to work...
$preReqLog = Get-ChildItem -Path (Get-Item $env:TEMP).FullName | Where-Object {$_.Name -like "PrerequisiteInstaller.*"} | Sort-Object -Descending -Property "LastWriteTime" | Select-Object -first 1
If ($preReqLog -eq $null)
{
Write-Warning "Could not find PrerequisiteInstaller log file"
}
Else
{
# Get error(s) from log but filter out false-positives
$preReqLastError = $preReqLog | Select-String -SimpleMatch -Pattern "Error" -Encoding Unicode | Where-Object {($_.Line -notlike "*Startup task*") -and ($_.Line -notlike "*`$operation*")}
If ($preReqLastError)
{
ForEach ($preReqError in ($preReqLastError | ForEach-Object {$_.Line})) {Write-Warning $preReqError}
$preReqLastReturncode = $preReqLog | Select-String -SimpleMatch -Pattern "Last return code" -Encoding Unicode | Select-Object -Last 1
If ($preReqLastReturnCode) {Write-Verbose $preReqLastReturncode.Line}
If (!($preReqLastReturncode -like "*(0)"))
{
Write-Warning $preReqLastReturncode.Line
If (($preReqLastReturncode -like "*-2145124329*") -or ($preReqLastReturncode -like "*2359302*") -or ($preReqLastReturncode -eq "5"))
{
Write-Host -ForegroundColor White " - A known issue occurred installing one of the prerequisites - retrying..."
InstallPreRequisites ([xml]$xmlInput)
}
ElseIf (($preReqLog | Select-String -SimpleMatch -Pattern "Error when enabling ASP.NET v4.0.30319" -Encoding Unicode) -or ($preReqLog | Select-String -SimpleMatch -Pattern "Error when enabling ASP.NET v4.5 with IIS" -Encoding Unicode))
{
# Account for new issue with Win2012 RC / R2 and SP2013
Write-Host -ForegroundColor White " - A known issue occurred configuring .NET 4 / IIS."
$preReqKnownIssueRestart = $true
}
ElseIf ($preReqLog | Select-String -SimpleMatch -Pattern "pending restart blocks the installation" -Encoding Unicode)
{
Write-Host -ForegroundColor White " - A pending restart blocks the installation."
$preReqKnownIssueRestart = $true
}
ElseIf ($preReqLog | Select-String -SimpleMatch -Pattern "Error: This tool supports Windows Server version 6.1 and version 6.2" -Encoding Unicode)
{
Write-Host -ForegroundColor White " - A known issue occurred (due to Win2012 R2), continuing."
##$preReqKnownIssueRestart = $true
}
Else
{
Invoke-Item -Path "$((Get-Item $env:TEMP).FullName)\$preReqLog"
Throw " - Review the log file and try to correct any error conditions."
}
}
}
# Look for restart requirement in log
$preReqRestartNeeded = ($preReqLog | Select-String -SimpleMatch -Pattern "0XBC2=3010" -Encoding Unicode) -or ($preReqLog | Select-String -SimpleMatch -Pattern "0X3E9=1001" -Encoding Unicode)
If ($preReqRestartNeeded -or $preReqKnownIssueRestart)
{
Write-Host -ForegroundColor White " - Setting AutoSPInstaller information in the registry..."
New-Item -Path "HKLM:\SOFTWARE\AutoSPInstaller\" -ErrorAction SilentlyContinue | Out-Null
$regKey = Get-Item -Path "HKLM:\SOFTWARE\AutoSPInstaller\"
$regKey | New-ItemProperty -Name "RestartRequired" -PropertyType String -Value "1" -Force | Out-Null
# We now also want to disable remote installs, or else each server will attempt to remote install to every *other* server after it reboots!
$regKey | New-ItemProperty -Name "CancelRemoteInstall" -PropertyType String -Value "1" -Force | Out-Null
$regKey | New-ItemProperty -Name "LogTime" -PropertyType String -Value $script:Logtime -ErrorAction SilentlyContinue | Out-Null
Throw " - One or more of the prerequisites requires a restart."
}
Write-Host -ForegroundColor White " - All Prerequisite Software installed successfully."
}
}
WriteLine
}
#endregion
#region Install SharePoint
# ===================================================================================
# Func: InstallSharePoint
# Desc: Installs the SharePoint binaries in unattended mode
# ===================================================================================
Function InstallSharePoint ([xml]$xmlInput)
{
WriteLine
$spYear = $xmlInput.Configuration.Install.SPVersion
$spInstalled = Get-SharePointInstall
If ($spInstalled)
{
Write-Host -ForegroundColor White " - SharePoint $spYear binaries appear to be already installed - skipping installation."
}
Else
{
# Install SharePoint Binaries
If (Test-Path "$env:SPbits\setup.exe")
{
Write-Host -ForegroundColor Cyan " - Installing SharePoint $spYear binaries..." -NoNewline
$startTime = Get-Date
Start-Process "$env:SPbits\setup.exe" -ArgumentList "/config `"$configFile`"" -WindowStyle Minimized
Show-Progress -Process setup -Color Cyan -Interval 5
$delta,$null = (New-TimeSpan -Start $startTime -End (Get-Date)).ToString() -split "\."
Write-Host -ForegroundColor White " - SharePoint $spYear setup completed in $delta."
If (-not $?)
{
Throw " - Error $LASTEXITCODE occurred running $env:SPbits\setup.exe"
}
# Parsing most recent SharePoint Server Setup log for errors or restart requirements, since $LASTEXITCODE doesn't seem to work...
$setupLog = Get-ChildItem -Path (Get-Item $env:TEMP).FullName | Where-Object {$_.Name -like "*SharePoint * Setup*"} | Sort-Object -Descending -Property "LastWriteTime" | Select-Object -first 1
If ($setupLog -eq $null)
{
Throw " - Could not find SharePoint Server Setup log file!"
}
# Get error(s) from log
$setupLastError = $setupLog | Select-String -SimpleMatch -Pattern "Error:" | Select-Object -Last 1
$setupSuccess = $setupLog | Select-String -SimpleMatch -Pattern "Successfully installed package: oserver"
# Look for a different success message if we are only installing Foundation
if ($xmlInput.Configuration.Install.SKU -eq "Foundation") {$setupSuccess = $setupLog | Select-String -SimpleMatch -Pattern "Successfully installed package: wss"}
If ($setupLastError -and !$setupSuccess)
{
Write-Warning $setupLastError.Line
Invoke-Item -Path "$((Get-Item $env:TEMP).FullName)\$setupLog"
Throw " - Review the log file and try to correct any error conditions."
}
# Look for restart requirement in log
$setupRestartNotNeeded = $setupLog | select-string -SimpleMatch -Pattern "System reboot is not pending."
If (!($setupRestartNotNeeded))