Examples/SQL-ClusterDB.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 |
#requires -Version 5 Configuration SQL { Import-DscResource -Module xSQLServer Import-DscResource -Module xFailoverCluster Node $AllNodes.NodeName { # Set LCM to reboot if needed LocalConfigurationManager { DebugMode = $true RebootNodeIfNeeded = $true } WindowsFeature "NET-Framework-Core" { Ensure = "Present" Name = "NET-Framework-Core" Source = $Node.SourcePath + "\WindowsServer2012R2\sources\sxs" } WindowsFeature "Failover-Clustering" { Ensure = "Present" Name = "Failover-Clustering" } WindowsFeature "RSAT-Clustering-PowerShell" { Ensure = "Present" Name = "RSAT-Clustering-PowerShell" } if($Node.NodeName -eq "CLDBA.contoso.com") { xCluster "CLDBx" { DependsOn = @( "[WindowsFeature]Failover-Clustering", "[WindowsFeature]RSAT-Clustering-PowerShell" ) Name = "CLDBx" StaticIPAddress = "192.168.1.251" DomainAdministratorCredential = $Node.InstallerServiceAccount } WaitForAll "CLDBx" { ResourceName = "[xCluster]CLDBx" NodeName = @( "CLDBB.contoso.com", "CLDBC.contoso.com", "CLDBD.contoso.com" ) Credential = $Node.InstallerServiceAccount RetryIntervalSec = 5 RetryCount = 720 } xClusterDisk "iSCSI" { DependsOn = "[WaitForAll]CLDBx" DiskFriendlyName = "MSFT Virtual HD SCSI Disk Device" DiskNumbers = "" } } else { WaitForAll "CLDBx" { ResourceName = "[xCluster]CLDBx" NodeName = "CLDBA.contoso.com" Credential = $Node.InstallerServiceAccount RetryIntervalSec = 5 RetryCount = 720 } xCluster "CLDBx" { DependsOn = "[WaitForAll]CLDBx" Name = "CLDBx" StaticIPAddress = "192.168.1.251" DomainAdministratorCredential = $Node.InstallerServiceAccount } } xSQLServerFailoverClusterSetup "PrepareMSSQLSERVER" { DependsOn = @( "[WindowsFeature]NET-Framework-Core", "[WindowsFeature]Failover-Clustering" ) Action = "Prepare" SourcePath = $Node.SourcePath SetupCredential = $Node.InstallerServiceAccount Features = "SQLENGINE,AS,IS" InstanceName = "MSSQLSERVER" FailoverClusterNetworkName = "CLSCDB" SQLSvcAccount = $Node.SQLServiceAccount } xSqlServerFirewall "FirewallMSSQLSERVER" { DependsOn = "[xSQLServerFailoverClusterSetup]PrepareMSSQLSERVER" SourcePath = $Node.SourcePath InstanceName = "MSSQLSERVER" Features = "SQLENGINE,AS,IS" } if($Node.NodeName -eq "CLDBA.contoso.com") { WaitForAll "Cluster" { NodeName = @( "CLDBB.contoso.com", "CLDBC.contoso.com", "CLDBD.contoso.com" ) ResourceName = "[xSQLServerFailoverClusterSetup]PrepareMSSQLSERVER" Credential = $Node.InstallerServiceAccount RetryIntervalSec = 5 RetryCount = 720 } xSQLServerFailoverClusterSetup "CompleteMSSQLSERVER" { DependsOn = @( "[WaitForAll]Cluster", "[xClusterDisk]iSCSI" ) Action = "Complete" SourcePath = $Node.SourcePath SetupCredential = $Node.InstallerServiceAccount Features = "SQLENGINE,AS,IS" InstanceName = "MSSQLSERVER" FailoverClusterNetworkName = "CLSCDB" InstallSQLDataDir = "E:\" ASDataDir = "F:\OLAP\Data" ASLogDir = "F:\OLAP\Log" ASBackupDir = "F:\OLAP\Backup" ASTempDir = "F:\OLAP\Temp" ASConfigDir = "F:\OLAP\Config" ISFileSystemFolder = "E:\Pacakges" FailoverClusterIPAddress = "192.168.1.250" SQLSvcAccount = $Node.SQLServiceAccount SQLSysAdminAccounts = $Node.AdminAccount ASSysAdminAccounts = $Node.AdminAccount } } } } $SecurePassword = ConvertTo-SecureString -String "Pass@word1" -AsPlainText -Force $DomainAdministratorCredential = New-Object System.Management.Automation.PSCredential ("CONTOSO\Administrator", $SecurePassword) $InstallerServiceAccount = New-Object System.Management.Automation.PSCredential ("CONTOSO\!Installer", $SecurePassword) $LocalSystemAccount = New-Object System.Management.Automation.PSCredential ("SYSTEM", $SecurePassword) $SQLServiceAccount = New-Object System.Management.Automation.PSCredential ("CONTOSO\!sql", $SecurePassword) $ConfigurationData = @{ AllNodes = @( @{ NodeName = "*" PSDscAllowPlainTextPassword = $true SourcePath = "\\RD01\Installer" DomainAdministratorCredential = $DomainAdministratorCredential InstallerServiceAccount = $InstallerServiceAccount LocalSystemAccount = $LocalSystemAccount SQLServiceAccount = $SQLServiceAccount AdminAccount = "CONTOSO\Administrator" } @{ NodeName = "CLDBA.contoso.com" } @{ NodeName = "CLDBB.contoso.com" } @{ NodeName = "CLDBC.contoso.com" } @{ NodeName = "CLDBD.contoso.com" } ) } foreach($Node in $ConfigurationData.AllNodes) { if($Node.NodeName -ne "*") { Start-Process -FilePath "robocopy.exe" -ArgumentList ("`"C:\Program Files\WindowsPowerShell\Modules`" `"\\" + $Node.NodeName + "\c$\Program Files\WindowsPowerShell\Modules`" /e /purge /xf") -NoNewWindow -Wait } } SQL -ConfigurationData $ConfigurationData Set-DscLocalConfigurationManager -Path .\SQL -Verbose Start-DscConfiguration -Path .\SQL -Verbose -Wait -Force |