-
Notifications
You must be signed in to change notification settings - Fork 225
/
MSFT_SqlSetup.psm1
2360 lines (1898 loc) · 77.5 KB
/
MSFT_SqlSetup.psm1
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
Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) `
-ChildPath 'SqlServerDscHelper.psm1')
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath 'CommonResourceHelper.psm1')
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlSetup'
<#
.SYNOPSIS
Returns the current state of the SQL Server features.
.PARAMETER Action
The action to be performed. Default value is 'Install'.
Possible values are 'Install', 'InstallFailoverCluster', 'AddNode', 'PrepareFailoverCluster', and 'CompleteFailoverCluster'.
.PARAMETER SourcePath
The path to the root of the source files for installation. I.e and UNC path to a shared resource. Environment variables can be used in the path.
.PARAMETER SourceCredential
Credentials used to access the path set in the parameter `SourcePath`. Using this parameter will trigger a copy
of the installation media to a temp folder on the target node. Setup will then be started from the temp folder on the target node.
For any subsequent calls to the resource, the parameter `SourceCredential` is used to evaluate what major version the file 'setup.exe'
has in the path set, again, by the parameter `SourcePath`.
If the path, that is assigned to parameter `SourcePath`, contains a leaf folder, for example '\\server\share\folder', then that leaf
folder will be used as the name of the temporary folder. If the path, that is assigned to parameter `SourcePath`, does not have a
leaf folder, for example '\\server\share', then a unique guid will be used as the name of the temporary folder.
.PARAMETER InstanceName
Name of the SQL instance to be installed.
.PARAMETER FailoverClusterNetworkName
Host name to be assigned to the clustered SQL Server instance.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter()]
[ValidateSet('Install','InstallFailoverCluster','AddNode','PrepareFailoverCluster','CompleteFailoverCluster')]
[System.String]
$Action = 'Install',
[Parameter()]
[System.String]
$SourcePath,
[Parameter()]
[System.Management.Automation.PSCredential]
$SourceCredential,
[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[Parameter()]
[System.String]
$FailoverClusterNetworkName
)
if ($Action -in @('CompleteFailoverCluster','InstallFailoverCluster','Addnode'))
{
$sqlHostName = $FailoverClusterNetworkName
}
else
{
$sqlHostName = $env:COMPUTERNAME
}
$InstanceName = $InstanceName.ToUpper()
$SourcePath = [Environment]::ExpandEnvironmentVariables($SourcePath)
if ($SourceCredential)
{
$newSmbMappingParameters = @{
RemotePath = $SourcePath
UserName = "$($SourceCredential.GetNetworkCredential().Domain)\$($SourceCredential.GetNetworkCredential().UserName)"
Password = $($SourceCredential.GetNetworkCredential().Password)
}
$null = New-SmbMapping @newSmbMappingParameters
}
$pathToSetupExecutable = Join-Path -Path $SourcePath -ChildPath 'setup.exe'
Write-Verbose -Message ($script:localizedData.UsingPath -f $pathToSetupExecutable)
$sqlVersion = Get-SqlMajorVersion -Path $pathToSetupExecutable
if ($SourceCredential)
{
Remove-SmbMapping -RemotePath $SourcePath -Force
}
if ($InstanceName -eq 'MSSQLSERVER')
{
$databaseServiceName = 'MSSQLSERVER'
$agentServiceName = 'SQLSERVERAGENT'
$fullTextServiceName = 'MSSQLFDLauncher'
$reportServiceName = 'ReportServer'
$analysisServiceName = 'MSSQLServerOLAPService'
}
else
{
$databaseServiceName = "MSSQL`$$InstanceName"
$agentServiceName = "SQLAgent`$$InstanceName"
$fullTextServiceName = "MSSQLFDLauncher`$$InstanceName"
$reportServiceName = "ReportServer`$$InstanceName"
$analysisServiceName = "MSOLAP`$$InstanceName"
}
$integrationServiceName = "MsDtsServer$($sqlVersion)0"
$features = ''
$services = Get-Service
Write-Verbose -Message $script:localizedData.EvaluateDatabaseEngineFeature
if ($services | Where-Object {$_.Name -eq $databaseServiceName})
{
Write-Verbose -Message $script:localizedData.DatabaseEngineFeatureFound
$features += 'SQLENGINE,'
$sqlServiceCimInstance = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$databaseServiceName'")
$agentServiceCimInstance = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$agentServiceName'")
$sqlServiceAccountUsername = $sqlServiceCimInstance.StartName
$agentServiceAccountUsername = $agentServiceCimInstance.StartName
$SqlSvcStartupType = ConvertTo-StartupType -StartMode $sqlServiceCimInstance.StartMode
$AgtSvcStartupType = ConvertTo-StartupType -StartMode $agentServiceCimInstance.StartMode
$fullInstanceId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' -Name $InstanceName).$InstanceName
# Check if Replication sub component is configured for this instance
$replicationRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$fullInstanceId\ConfigurationState"
Write-Verbose -Message ($script:localizedData.EvaluateReplicationFeature -f $replicationRegistryPath)
$isReplicationInstalled = (Get-ItemProperty -Path $replicationRegistryPath).SQL_Replication_Core_Inst
if ($isReplicationInstalled -eq 1)
{
Write-Verbose -Message $script:localizedData.ReplicationFeatureFound
$features += 'REPLICATION,'
}
else
{
Write-Verbose -Message $script:localizedData.ReplicationFeatureNotFound
}
# Check if Data Quality Client sub component is configured
$dataQualityClientRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($sqlVersion)0\ConfigurationState"
Write-Verbose -Message ($script:localizedData.EvaluateDataQualityClientFeature -f $dataQualityClientRegistryPath)
$isDQCInstalled = (Get-ItemProperty -Path $dataQualityClientRegistryPath).SQL_DQ_CLIENT_Full
if ($isDQCInstalled -eq 1)
{
Write-Verbose -Message $script:localizedData.DataQualityClientFeatureFound
$features += 'DQC,'
}
else
{
Write-Verbose -Message $script:localizedData.DataQualityClientFeatureNotFound
}
# Check if Data Quality Services sub component is configured
$dataQualityServicesRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($sqlVersion)0\DQ\*"
Write-Verbose -Message ($script:localizedData.EvaluateDataQualityServicesFeature -f $dataQualityServicesRegistryPath)
$isDQInstalled = (Get-ItemProperty -Path $dataQualityServicesRegistryPath -ErrorAction SilentlyContinue)
if ($isDQInstalled)
{
Write-Verbose -Message $script:localizedData.DataQualityServicesFeatureFound
$features += 'DQ,'
}
else
{
Write-Verbose -Message $script:localizedData.DataQualityServicesFeatureNotFound
}
$instanceId = $fullInstanceId.Split('.')[1]
$instanceDirectory = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$fullInstanceId\Setup" -Name 'SqlProgramDir').SqlProgramDir.Trim("\")
$databaseServer = Connect-SQL -SQLServer $sqlHostName -SQLInstanceName $InstanceName
$sqlCollation = $databaseServer.Collation
$sqlSystemAdminAccounts = @()
foreach ($sqlUser in $databaseServer.Logins)
{
foreach ($sqlRole in $sqlUser.ListMembers())
{
if ($sqlRole -like 'sysadmin')
{
$sqlSystemAdminAccounts += $sqlUser.Name
}
}
}
if ($databaseServer.LoginMode -eq 'Mixed')
{
$securityMode = 'SQL'
}
else
{
$securityMode = 'Windows'
}
$installSQLDataDirectory = $databaseServer.InstallDataDirectory
$sqlUserDatabaseDirectory = $databaseServer.DefaultFile
$sqlUserDatabaseLogDirectory = $databaseServer.DefaultLog
$sqlBackupDirectory = $databaseServer.BackupDirectory
if ($databaseServer.IsClustered)
{
Write-Verbose -Message $script:localizedData.ClusterInstanceFound
$clusteredSqlInstance = Get-CimInstance -Namespace root/MSCluster -ClassName MSCluster_Resource -Filter "Type = 'SQL Server'" |
Where-Object { $_.PrivateProperties.InstanceName -eq $InstanceName }
if (!$clusteredSqlInstance)
{
$errorMessage = $script:localizedData.FailoverClusterResourceNotFound -f $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
Write-Verbose -Message $script:localizedData.FailoverClusterResourceFound
$clusteredSqlGroup = $clusteredSqlInstance | Get-CimAssociatedInstance -ResultClassName MSCluster_ResourceGroup
$clusteredSqlNetworkName = $clusteredSqlGroup | Get-CimAssociatedInstance -ResultClassName MSCluster_Resource |
Where-Object { $_.Type -eq "Network Name" }
$clusteredSqlIPAddress = ($clusteredSqlNetworkName | Get-CimAssociatedInstance -ResultClassName MSCluster_Resource |
Where-Object { $_.Type -eq "IP Address" }).PrivateProperties.Address
# Extract the required values
$clusteredSqlGroupName = $clusteredSqlGroup.Name
$clusteredSqlHostname = $clusteredSqlNetworkName.PrivateProperties.DnsName
}
else
{
Write-Verbose -Message $script:localizedData.ClusterInstanceNotFound
}
}
else
{
Write-Verbose -Message $script:localizedData.DatabaseEngineFeatureNotFound
}
Write-Verbose -Message $script:localizedData.EvaluateFullTextFeature
if ($services | Where-Object {$_.Name -eq $fullTextServiceName})
{
Write-Verbose -Message $script:localizedData.FullTextFeatureFound
$features += 'FULLTEXT,'
$fullTextServiceAccountUsername = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$fullTextServiceName'").StartName
}
else
{
Write-Verbose -Message $script:localizedData.FullTextFeatureNotFound
}
Write-Verbose -Message $script:localizedData.EvaluateReportingServicesFeature
if ($services | Where-Object {$_.Name -eq $reportServiceName})
{
Write-Verbose -Message $script:localizedData.ReportingServicesFeatureFound
$features += 'RS,'
$reportingServiceCimInstance = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$reportServiceName'")
$reportingServiceAccountUsername = $reportingServiceCimInstance.StartName
$RsSvcStartupType = ConvertTo-StartupType -StartMode $reportingServiceCimInstance.StartMode
}
else
{
Write-Verbose -Message $script:localizedData.ReportingServicesFeatureNotFound
}
Write-Verbose -Message $script:localizedData.EvaluateAnalysisServicesFeature
if ($services | Where-Object {$_.Name -eq $analysisServiceName})
{
Write-Verbose -Message $script:localizedData.AnalysisServicesFeatureFound
$features += 'AS,'
$analysisServiceCimInstance = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$analysisServiceName'")
$analysisServiceAccountUsername = $analysisServiceCimInstance.StartName
$AsSvcStartupType = ConvertTo-StartupType -StartMode $analysisServiceCimInstance.StartMode
$analysisServer = Connect-SQLAnalysis -SQLServer $sqlHostName -SQLInstanceName $InstanceName
$analysisCollation = $analysisServer.ServerProperties['CollationName'].Value
$analysisDataDirectory = $analysisServer.ServerProperties['DataDir'].Value
$analysisTempDirectory = $analysisServer.ServerProperties['TempDir'].Value
$analysisLogDirectory = $analysisServer.ServerProperties['LogDir'].Value
$analysisBackupDirectory = $analysisServer.ServerProperties['BackupDir'].Value
<#
The property $analysisServer.ServerMode.value__ contains the
server mode (aka deployment mode) value 0, 1 or 2. See DeploymentMode
here https://docs.microsoft.com/en-us/sql/analysis-services/server-properties/general-properties.
The property $analysisServer.ServerMode contains the display name of
the property value__. See more information here
https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.core.server.servermode.aspx.
#>
$analysisServerMode = $analysisServer.ServerMode.ToString().ToUpper()
$analysisSystemAdminAccounts = [System.String[]] $analysisServer.Roles['Administrators'].Members.Name
$analysisConfigDirectory = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$analysisServiceName" -Name 'ImagePath').ImagePath.Replace(' -s ',',').Split(',')[1].Trim('"')
}
else
{
Write-Verbose -Message $script:localizedData.AnalysisServicesFeatureNotFound
}
Write-Verbose -Message $script:localizedData.EvaluateIntegrationServicesFeature
if ($services | Where-Object {$_.Name -eq $integrationServiceName})
{
Write-Verbose -Message $script:localizedData.IntegrationServicesFeatureFound
$features += 'IS,'
$integrationServiceCimInstance = (Get-CimInstance -ClassName Win32_Service -Filter "Name = '$integrationServiceName'")
$integrationServiceAccountUsername = $integrationServiceCimInstance.StartName
$IsSvcStartupType = ConvertTo-StartupType -StartMode $integrationServiceCimInstance.StartMode
}
else
{
Write-Verbose -Message $script:localizedData.IntegrationServicesFeatureNotFound
}
# Check if Documentation Components "BOL" is configured
$documentationComponentsRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($sqlVersion)0\ConfigurationState"
Write-Verbose -Message ($script:localizedData.EvaluateDocumentationComponentsFeature -f $documentationComponentsRegistryPath)
$isBOLInstalled = (Get-ItemProperty -Path $documentationComponentsRegistryPath -ErrorAction SilentlyContinue).SQL_BOL_Components
if ($isBOLInstalled -eq 1)
{
Write-Verbose -Message $script:localizedData.DocumentationComponentsFeatureFound
$features += 'BOL,'
}
else
{
Write-Verbose -Message $script:localizedData.DocumentationComponentsFeatureNotFound
}
$clientComponentsFullRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($sqlVersion)0\Tools\Setup\Client_Components_Full"
$registryClientComponentsFullFeatureList = (Get-ItemProperty -Path $clientComponentsFullRegistryPath -ErrorAction SilentlyContinue).FeatureList
Write-Verbose -Message ($script:localizedData.EvaluateClientConnectivityToolsFeature -f $clientComponentsFullRegistryPath)
if ($registryClientComponentsFullFeatureList -like '*Connectivity_FNS=3*')
{
Write-Verbose -Message $script:localizedData.ClientConnectivityToolsFeatureFound
$features += 'CONN,'
}
else
{
Write-Verbose -Message $script:localizedData.ClientConnectivityToolsFeatureNotFound
}
Write-Verbose -Message ($script:localizedData.EvaluateClientConnectivityBackwardsCompatibilityToolsFeature -f $clientComponentsFullRegistryPath)
if ($registryClientComponentsFullFeatureList -like '*Tools_Legacy_FNS=3*')
{
Write-Verbose -Message $script:localizedData.ClientConnectivityBackwardsCompatibilityToolsFeatureFound
$features += 'BC,'
}
else
{
Write-Verbose -Message $script:localizedData.ClientConnectivityBackwardsCompatibilityToolsFeatureNotFound
}
Write-Verbose -Message ($script:localizedData.EvaluateClientToolsSdkFeature -f $clientComponentsFullRegistryPath)
if (($registryClientComponentsFullFeatureList -like '*SDK_Full=3*') -and ($registryClientComponentsFullFeatureList -like '*SDK_FNS=3*'))
{
Write-Verbose -Message $script:localizedData.ClientToolsSdkFeatureFound
$features += 'SDK,'
}
else
{
Write-Verbose -Message $script:localizedData.ClientToolsSdkFeatureNotFound
}
# Check if MDS sub component is configured for this server
$masterDataServicesFullRegistryPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($sqlVersion)0\ConfigurationState"
Write-Verbose -Message ($script:localizedData.EvaluateMasterDataServicesFeature -f $masterDataServicesFullRegistryPath)
$isMDSInstalled = (Get-ItemProperty -Path $masterDataServicesFullRegistryPath -ErrorAction SilentlyContinue).MDSCoreFeature
if ($isMDSInstalled -eq 1)
{
Write-Verbose -Message $script:localizedData.MasterDataServicesFeatureFound
$features += 'MDS,'
}
else
{
Write-Verbose -Message $script:localizedData.MasterDataServicesFeatureNotFound
}
$registryUninstallPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
# Verify if SQL Server Management Studio 2008 or SQL Server Management Studio 2008 R2 (major version 10) is installed
$installedProductSqlServerManagementStudio2008R2 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{72AB7E6F-BC24-481E-8C45-1AB5B3DD795D}'
) -ErrorAction SilentlyContinue
# Verify if SQL Server Management Studio 2012 (major version 11) is installed
$installedProductSqlServerManagementStudio2012 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{A7037EB2-F953-4B12-B843-195F4D988DA1}'
) -ErrorAction SilentlyContinue
# Verify if SQL Server Management Studio 2014 (major version 12) is installed
$installedProductSqlServerManagementStudio2014 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{75A54138-3B98-4705-92E4-F619825B121F}'
) -ErrorAction SilentlyContinue
if (
($sqlVersion -eq 10 -and $installedProductSqlServerManagementStudio2008R2) -or
($sqlVersion -eq 11 -and $installedProductSqlServerManagementStudio2012) -or
($sqlVersion -eq 12 -and $installedProductSqlServerManagementStudio2014)
)
{
$features += 'SSMS,'
}
# Evaluating if SQL Server Management Studio Advanced 2008 or SQL Server Management Studio Advanced 2008 R2 (major version 10) is installed
$installedProductSqlServerManagementStudioAdvanced2008R2 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{B5FE23CC-0151-4595-84C3-F1DE6F44FE9B}'
) -ErrorAction SilentlyContinue
# Evaluating if SQL Server Management Studio Advanced 2012 (major version 11) is installed
$installedProductSqlServerManagementStudioAdvanced2012 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{7842C220-6E9A-4D5A-AE70-0E138271F883}'
) -ErrorAction SilentlyContinue
# Evaluating if SQL Server Management Studio Advanced 2014 (major version 12) is installed
$installedProductSqlServerManagementStudioAdvanced2014 = Get-ItemProperty -Path (
Join-Path -Path $registryUninstallPath -ChildPath '{B5ECFA5C-AC4F-45A4-A12E-A76ABDD9CCBA}'
) -ErrorAction SilentlyContinue
if (
($sqlVersion -eq 10 -and $installedProductSqlServerManagementStudioAdvanced2008R2) -or
($sqlVersion -eq 11 -and $installedProductSqlServerManagementStudioAdvanced2012) -or
($sqlVersion -eq 12 -and $installedProductSqlServerManagementStudioAdvanced2014)
)
{
$features += 'ADV_SSMS,'
}
$features = $features.Trim(',')
if ($features)
{
$registryInstallerComponentsPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components'
switch ($sqlVersion)
{
{ $_ -in ('10','11','12','13','14') }
{
$registryKeySharedDir = 'FEE2E540D20152D4597229B6CFBC0A69'
$registryKeySharedWOWDir = 'A79497A344129F64CA7D69C56F5DD8B4'
}
}
if ($registryKeySharedDir)
{
$installSharedDir = Get-FirstItemPropertyValue -Path (Join-Path -Path $registryInstallerComponentsPath -ChildPath $registryKeySharedDir)
}
if ($registryKeySharedWOWDir)
{
$installSharedWOWDir = Get-FirstItemPropertyValue -Path (Join-Path -Path $registryInstallerComponentsPath -ChildPath $registryKeySharedWOWDir)
}
}
return @{
SourcePath = $SourcePath
Features = $features
InstanceName = $InstanceName
InstanceID = $instanceID
InstallSharedDir = $installSharedDir
InstallSharedWOWDir = $installSharedWOWDir
InstanceDir = $instanceDirectory
SQLSvcAccountUsername = $sqlServiceAccountUsername
SqlSvcStartupType = $SqlSvcStartupType
AgtSvcAccountUsername = $agentServiceAccountUsername
AgtSvcStartupType = $AgtSvcStartupType
SQLCollation = $sqlCollation
SQLSysAdminAccounts = $sqlSystemAdminAccounts
SecurityMode = $securityMode
InstallSQLDataDir = $installSQLDataDirectory
SQLUserDBDir = $sqlUserDatabaseDirectory
SQLUserDBLogDir = $sqlUserDatabaseLogDirectory
SQLTempDBDir = $null
SQLTempDBLogDir = $null
SQLBackupDir = $sqlBackupDirectory
FTSvcAccountUsername = $fullTextServiceAccountUsername
RSSvcAccountUsername = $reportingServiceAccountUsername
RsSvcStartupType = $RsSvcStartupType
ASSvcAccountUsername = $analysisServiceAccountUsername
AsSvcStartupType = $AsSvcStartupType
ASCollation = $analysisCollation
ASSysAdminAccounts = $analysisSystemAdminAccounts
ASDataDir = $analysisDataDirectory
ASLogDir = $analysisLogDirectory
ASBackupDir = $analysisBackupDirectory
ASTempDir = $analysisTempDirectory
ASConfigDir = $analysisConfigDirectory
ASServerMode = $analysisServerMode
ISSvcAccountUsername = $integrationServiceAccountUsername
IsSvcStartupType = $IsSvcStartupType
FailoverClusterGroupName = $clusteredSqlGroupName
FailoverClusterNetworkName = $clusteredSqlHostname
FailoverClusterIPAddress = $clusteredSqlIPAddress
}
}
<#
.SYNOPSIS
Installs the SQL Server features to the node.
.PARAMETER Action
The action to be performed. Default value is 'Install'.
Possible values are 'Install', 'InstallFailoverCluster', 'AddNode', 'PrepareFailoverCluster', and 'CompleteFailoverCluster'.
.PARAMETER SourcePath
The path to the root of the source files for installation. I.e and UNC path to a shared resource. Environment variables can be used in the path.
.PARAMETER SourceCredential
Credentials used to access the path set in the parameter `SourcePath`. Using this parameter will trigger a copy
of the installation media to a temp folder on the target node. Setup will then be started from the temp folder on the target node.
For any subsequent calls to the resource, the parameter `SourceCredential` is used to evaluate what major version the file 'setup.exe'
has in the path set, again, by the parameter `SourcePath`.
If the path, that is assigned to parameter `SourcePath`, contains a leaf folder, for example '\\server\share\folder', then that leaf
folder will be used as the name of the temporary folder. If the path, that is assigned to parameter `SourcePath`, does not have a
leaf folder, for example '\\server\share', then a unique guid will be used as the name of the temporary folder.
.PARAMETER SuppressReboot
Suppressed reboot.
.PARAMETER ForceReboot
Forces reboot.
.PARAMETER Features
SQL features to be installed.
.PARAMETER InstanceName
Name of the SQL instance to be installed.
.PARAMETER InstanceID
SQL instance ID, if different from InstanceName.
.PARAMETER ProductKey
Product key for licensed installations.
.PARAMETER UpdateEnabled
Enabled updates during installation.
.PARAMETER UpdateSource
Path to the source of updates to be applied during installation.
.PARAMETER SQMReporting
Enable customer experience reporting.
.PARAMETER ErrorReporting
Enable error reporting.
.PARAMETER InstallSharedDir
Installation path for shared SQL files.
.PARAMETER InstallSharedWOWDir
Installation path for x86 shared SQL files.
.PARAMETER InstanceDir
Installation path for SQL instance files.
.PARAMETER SQLSvcAccount
Service account for the SQL service.
.PARAMETER AgtSvcAccount
Service account for the SQL Agent service.
.PARAMETER SQLCollation
Collation for SQL.
.PARAMETER SQLSysAdminAccounts
Array of accounts to be made SQL administrators.
.PARAMETER SecurityMode
Security mode to apply to the
SQL Server instance. 'SQL' indicates mixed-mode authentication while
'Windows' indicates Windows authentication.
Default is Windows. { *Windows* | SQL }
.PARAMETER SAPwd
SA password, if SecurityMode is set to 'SQL'.
.PARAMETER InstallSQLDataDir
Root path for SQL database files.
.PARAMETER SQLUserDBDir
Path for SQL database files.
.PARAMETER SQLUserDBLogDir
Path for SQL log files.
.PARAMETER SQLTempDBDir
Path for SQL TempDB files.
.PARAMETER SQLTempDBLogDir
Path for SQL TempDB log files.
.PARAMETER SQLBackupDir
Path for SQL backup files.
.PARAMETER FTSvcAccount
Service account for the Full Text service.
.PARAMETER RSSvcAccount
Service account for Reporting Services service.
.PARAMETER ASSvcAccount
Service account for Analysis Services service.
.PARAMETER ASCollation
Collation for Analysis Services.
.PARAMETER ASSysAdminAccounts
Array of accounts to be made Analysis Services admins.
.PARAMETER ASDataDir
Path for Analysis Services data files.
.PARAMETER ASLogDir
Path for Analysis Services log files.
.PARAMETER ASBackupDir
Path for Analysis Services backup files.
.PARAMETER ASTempDir
Path for Analysis Services temp files.
.PARAMETER ASConfigDir
Path for Analysis Services config.
.PARAMETER ASServerMode
The server mode for SQL Server Analysis Services instance. The default is
to install in Multidimensional mode. Valid values in a cluster scenario
are MULTIDIMENSIONAL or TABULAR. Parameter ASServerMode is case-sensitive.
All values must be expressed in upper case.
{ MULTIDIMENSIONAL | TABULAR | POWERPIVOT }.
.PARAMETER ISSvcAccount
Service account for Integration Services service.
.PARAMETER SqlSvcStartupType
Specifies the startup mode for SQL Server Engine service.
.PARAMETER AgtSvcStartupType
Specifies the startup mode for SQL Server Agent service.
.PARAMETER AsSvcStartupType
Specifies the startup mode for SQL Server Analysis service.
.PARAMETER IsSvcStartupType
Specifies the startup mode for SQL Server Integration service.
.PARAMETER RsSvcStartupType
Specifies the startup mode for SQL Server Report service.
.PARAMETER BrowserSvcStartupType
Specifies the startup mode for SQL Server Browser service.
.PARAMETER FailoverClusterGroupName
The name of the resource group to create for the clustered SQL Server instance. Default is 'SQL Server (InstanceName)'.
.PARAMETER FailoverClusterIPAddress
Array of IP Addresses to be assigned to the clustered SQL Server instance.
.PARAMETER FailoverClusterNetworkName
Host name to be assigned to the clustered SQL Server instance.
.PARAMETER SetupProcessTimeout
The timeout, in seconds, to wait for the setup process to finish. Default value is 7200 seconds (2 hours). If the setup process does not finish before this time, and error will be thrown.
#>
function Set-TargetResource
{
<#
Suppressing this rule because $global:DSCMachineStatus is used to trigger
a reboot, either by force or when there are pending changes.
#>
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
<#
Suppressing this rule because $global:DSCMachineStatus is only set,
never used (by design of Desired State Configuration).
#>
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]
[CmdletBinding()]
param
(
[Parameter()]
[ValidateSet('Install','InstallFailoverCluster','AddNode','PrepareFailoverCluster','CompleteFailoverCluster')]
[System.String]
$Action = 'Install',
[Parameter()]
[System.String]
$SourcePath,
[Parameter()]
[System.Management.Automation.PSCredential]
$SourceCredential,
[Parameter()]
[System.Boolean]
$SuppressReboot,
[Parameter()]
[System.Boolean]
$ForceReboot,
[Parameter()]
[System.String]
$Features,
[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[Parameter()]
[System.String]
$InstanceID,
[Parameter()]
[System.String]
$ProductKey,
[Parameter()]
[System.String]
$UpdateEnabled,
[Parameter()]
[System.String]
$UpdateSource,
[Parameter()]
[System.String]
$SQMReporting,
[Parameter()]
[System.String]
$ErrorReporting,
[Parameter()]
[System.String]
$InstallSharedDir,
[Parameter()]
[System.String]
$InstallSharedWOWDir,
[Parameter()]
[System.String]
$InstanceDir,
[Parameter()]
[System.Management.Automation.PSCredential]
$SQLSvcAccount,
[Parameter()]
[System.Management.Automation.PSCredential]
$AgtSvcAccount,
[Parameter()]
[System.String]
$SQLCollation,
[Parameter()]
[System.String[]]
$SQLSysAdminAccounts,
[Parameter()]
[ValidateSet('SQL', 'Windows')]
[System.String]
$SecurityMode,
[Parameter()]
[System.Management.Automation.PSCredential]
$SAPwd,
[Parameter()]
[System.String]
$InstallSQLDataDir,
[Parameter()]
[System.String]
$SQLUserDBDir,
[Parameter()]
[System.String]
$SQLUserDBLogDir,
[Parameter()]
[System.String]
$SQLTempDBDir,
[Parameter()]
[System.String]
$SQLTempDBLogDir,
[Parameter()]
[System.String]
$SQLBackupDir,
[Parameter()]
[System.Management.Automation.PSCredential]
$FTSvcAccount,
[Parameter()]
[System.Management.Automation.PSCredential]
$RSSvcAccount,
[Parameter()]
[System.Management.Automation.PSCredential]
$ASSvcAccount,
[Parameter()]
[System.String]
$ASCollation,
[Parameter()]
[System.String[]]
$ASSysAdminAccounts,
[Parameter()]
[System.String]
$ASDataDir,
[Parameter()]
[System.String]
$ASLogDir,
[Parameter()]
[System.String]
$ASBackupDir,
[Parameter()]
[System.String]
$ASTempDir,
[Parameter()]
[System.String]
$ASConfigDir,
[Parameter()]
[ValidateSet('MULTIDIMENSIONAL','TABULAR','POWERPIVOT', IgnoreCase = $false)]
[System.String]
$ASServerMode,
[Parameter()]
[System.Management.Automation.PSCredential]
$ISSvcAccount,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$SqlSvcStartupType,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$AgtSvcStartupType,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$IsSvcStartupType,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$AsSvcStartupType,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$RsSvcStartupType,
[Parameter()]
[System.String]
[ValidateSet('Automatic', 'Disabled', 'Manual')]
$BrowserSvcStartupType,
[Parameter()]
[System.String]
$FailoverClusterGroupName = "SQL Server ($InstanceName)",
[Parameter()]
[System.String[]]
$FailoverClusterIPAddress,
[Parameter()]
[System.String]
$FailoverClusterNetworkName,
[Parameter()]
[System.UInt32]
$SetupProcessTimeout = 7200
)
$getTargetResourceParameters = @{
Action = $Action
SourcePath = $SourcePath
SourceCredential = $SourceCredential
InstanceName = $InstanceName
FailoverClusterNetworkName = $FailoverClusterNetworkName
}
$getTargetResourceResult = Get-TargetResource @getTargetResourceParameters
$InstanceName = $InstanceName.ToUpper()
$parametersToEvaluateTrailingSlash = @(
'InstanceDir',
'InstallSharedDir',
'InstallSharedWOWDir',
'InstallSQLDataDir',
'SQLUserDBDir',
'SQLUserDBLogDir',
'SQLTempDBDir',
'SQLTempDBLogDir',
'SQLBackupDir',
'ASDataDir',
'ASLogDir',
'ASBackupDir',
'ASTempDir',
'ASConfigDir',
'UpdateSource'
)
# Remove trailing slash ('\') from paths
foreach ($parameterName in $parametersToEvaluateTrailingSlash)
{
if ($PSBoundParameters.ContainsKey($parameterName))
{
$parameterValue = Get-Variable -Name $parameterName -ValueOnly
# Trim backslash, but only if the path contains a full path and not just a qualifier.
if ($parameterValue -and $parameterValue -notmatch '^[a-zA-Z]:\\$')
{
Set-Variable -Name $parameterName -Value $parameterValue.TrimEnd('\')
}
# If the path only contains a qualifier but no backslash ('M:'), then a backslash is added ('M:\').
if ($parameterValue -match '^[a-zA-Z]:$')
{
Set-Variable -Name $parameterName -Value "$parameterValue\"
}
}
}
$SourcePath = [Environment]::ExpandEnvironmentVariables($SourcePath)
if ($SourceCredential)
{
$newSmbMappingParameters = @{
RemotePath = $SourcePath
UserName = "$($SourceCredential.GetNetworkCredential().Domain)\$($SourceCredential.GetNetworkCredential().UserName)"
Password = $($SourceCredential.GetNetworkCredential().Password)
}
$null = New-SmbMapping @newSmbMappingParameters
# Create a destination folder so the media files aren't written to the root of the Temp folder.
$mediaDestinationFolder = Split-Path -Path $SourcePath -Leaf
if (-not $mediaDestinationFolder )
{
$mediaDestinationFolder = New-Guid | Select-Object -ExpandProperty Guid
}
$mediaDestinationPath = Join-Path -Path (Get-TemporaryFolder) -ChildPath $mediaDestinationFolder
Write-Verbose -Message ($script:localizedData.RobocopyIsCopying -f $SourcePath, $mediaDestinationPath)
Copy-ItemWithRobocopy -Path $SourcePath -DestinationPath $mediaDestinationPath
Remove-SmbMapping -RemotePath $SourcePath -Force
$SourcePath = $mediaDestinationPath
}
$pathToSetupExecutable = Join-Path -Path $SourcePath -ChildPath 'setup.exe'