|
7 | 7 | $ClusterName="Exp-Cluster" |
8 | 8 | $vSwitchName="vSwitch" |
9 | 9 |
|
10 | | - # Install features for management on server |
| 10 | + # Install features for management |
11 | 11 | Install-WindowsFeature -Name RSAT-DHCP,RSAT-Clustering,RSAT-Clustering-Mgmt,RSAT-Clustering-PowerShell,RSAT-Hyper-V-Tools |
12 | 12 |
|
13 | 13 | # Install features on server |
|
25 | 25 | do{$Test= Test-NetConnection -ComputerName $Server -CommonTCPPort WINRM}while ($test.TcpTestSucceeded -eq $False) |
26 | 26 | #} |
27 | 27 | # create vSwitch from first connected NIC |
28 | | - $NetAdapterName=(Get-NetAdapter -Cimsession $Server | Where-Object HardwareInterface -eq $True | Where-Object Status -eq UP | Sort-Object InterfaceAlias | Select-Object -First 1).InterfaceAlias |
29 | | - New-VMSwitch -Cimsession $Server -Name $vSwitchName -EnableEmbeddedTeaming $TRUE -NetAdapterName $NetAdapterName -EnableIov $true |
| 28 | + $NetAdapterName=(Get-NetAdapter -CimSession $Server | Where-Object HardwareInterface -eq $True | Where-Object Status -eq UP | Sort-Object InterfaceAlias | Select-Object -First 1).InterfaceAlias |
| 29 | + New-VMSwitch -CimSession $Server -Name $vSwitchName -EnableEmbeddedTeaming $TRUE -NetAdapterName $NetAdapterName -EnableIov $true |
30 | 30 |
|
31 | 31 | #rename vNIC |
32 | | - Rename-VMNetworkAdapter -Cimsession $Server -ManagementOS -Name $vSwitchName -NewName Management |
| 32 | + Rename-VMNetworkAdapter -CimSession $Server -ManagementOS -Name $vSwitchName -NewName Management |
33 | 33 |
|
34 | 34 | #create cluster with Distributed Network Name (to not consume extra IP, because why not) |
35 | 35 | New-Cluster -Name $ClusterName -Node $Server -ManagementPointNetworkType "Distributed" |
|
125 | 125 | New-Item -Path "\\$ClusterName\ClusterStorage$\$VolumeFriendlyName\$VMName\Virtual Hard Disks" -ItemType Directory |
126 | 126 | Copy-Item -Path $VHDPath -Destination "\\$ClusterName\ClusterStorage$\$VolumeFriendlyName\$VMName\Virtual Hard Disks\$VMName.vhdx" |
127 | 127 | $VM=New-VM -Name $VMName -MemoryStartupBytes 512MB -Generation 2 -Path "c:\ClusterStorage\$VolumeFriendlyName\" -VHDPath "c:\ClusterStorage\$VolumeFriendlyName\$VMName\Virtual Hard Disks\$VMName.vhdx" -CimSession ((Get-ClusterNode -Cluster $ClusterName).Name | Get-Random) |
128 | | - |
| 128 | + #start VM |
| 129 | + $VM | Start-VM |
129 | 130 | }else{ |
130 | 131 | Invoke-Command -ComputerName ((Get-ClusterNode -Cluster $ClusterName).Name | Get-Random) -ScriptBlock { |
131 | 132 | #create some fake VMs |
132 | | - $VM=New-VM -Name $using:VMName -NewVHDPath "c:\ClusterStorage\$($using:VolumeFriendlyName)\$($using:VMName)\Virtual Hard Disks\$($using:VMName).vhdx" -NewVHDSizeBytes 32GB -SwitchName $using:vSwitchName -Generation 2 -Path "c:\ClusterStorage\$($using:VolumeFriendlyName)\" -MemoryStartupBytes 32MB |
| 133 | + New-VM -Name $using:VMName -NewVHDPath "c:\ClusterStorage\$($using:VolumeFriendlyName)\$($using:VMName)\Virtual Hard Disks\$($using:VMName).vhdx" -NewVHDSizeBytes 32GB -SwitchName $using:vSwitchName -Generation 2 -Path "c:\ClusterStorage\$($using:VolumeFriendlyName)\" -MemoryStartupBytes 32MB |
133 | 134 | } |
134 | 135 | } |
135 | 136 | #make it HA |
136 | 137 | Add-ClusterVirtualMachineRole -VMName $VMName -Cluster $ClusterName |
137 | | - #start VM |
138 | | - $VM | Start-VM |
139 | 138 | #endregion |
140 | 139 | #endregion |
141 | 140 |
|
|
153 | 152 | Restart-Computer -ComputerName $SecondNodeName -Protocol WSMan -Wait -For PowerShell |
154 | 153 | #failsafe - sometimes it evaluates, that servers completed restart after first restart (hyper-v needs 2) |
155 | 154 | Start-sleep 20 |
156 | | - #make sure computers are restarted |
157 | | - #Foreach ($Server in $Servers){ |
158 | | - do{$Test= Test-NetConnection -ComputerName $SecondNodeName -CommonTCPPort WINRM}while ($test.TcpTestSucceeded -eq $False) |
159 | | - #} |
| 155 | + #make sure computer is restarted |
| 156 | + do{$Test= Test-NetConnection -ComputerName $SecondNodeName -CommonTCPPort WINRM}while ($test.TcpTestSucceeded -eq $False) |
160 | 157 | #endregion |
161 | 158 |
|
162 | 159 | #region configure networking (assuming scalable, converged networking). |
|
180 | 177 | #create vSwitch on second node |
181 | 178 | #create vSwitch |
182 | 179 | $NetAdapterNames=(Get-NetAdapter -CimSession $SecondNodeName | Where-Object HardwareInterface -eq $True | Where-Object Status -eq UP | Sort-Object InterfaceAlias).InterfaceAlias |
183 | | - New-VMSwitch -Cimsession $SecondNodeName -Name $vSwitchName -EnableEmbeddedTeaming $TRUE -NetAdapterName $NetAdapterNames -EnableIov $true |
| 180 | + New-VMSwitch -CimSession $SecondNodeName -Name $vSwitchName -EnableEmbeddedTeaming $True -NetAdapterName $NetAdapterNames -EnableIov $true |
184 | 181 | #rename vNIC |
185 | | - Rename-VMNetworkAdapter -Cimsession $SecondNodeName -ManagementOS -Name $vSwitchName -NewName Management |
| 182 | + Rename-VMNetworkAdapter -CimSession $SecondNodeName -ManagementOS -Name $vSwitchName -NewName Management |
186 | 183 |
|
187 | 184 | #add SMB vNICs and configure IP |
188 | 185 | foreach ($Server in ($FirstNodeName,$SecondNodeName)){ |
|
195 | 192 | Add-VMNetworkAdapter -ManagementOS -Name "SMB$TwoDigitNumber" -SwitchName $vSwitchName -CimSession $Server |
196 | 193 | } |
197 | 194 |
|
198 | | - #assign IP Adresses |
| 195 | + #assign IP Addresses |
199 | 196 | foreach ($number in (1..$SMBvNICsCount)){ |
200 | 197 | $TwoDigitNumber="{0:D2}" -f $Number |
201 | 198 | if ($number % 2 -eq 1){ |
|
349 | 346 | #endregion |
350 | 347 |
|
351 | 348 | #region configure pool fault domain to be Storage Scale Unit and create new volume |
352 | | - #config |
| 349 | + #Config |
353 | 350 | $ClusterName="Exp-Cluster" |
354 | 351 | $VolumeFriendlyName="TwoNodesMirror" |
| 352 | + $VolumeSize=1TB |
355 | 353 |
|
356 | 354 | #configure storage pool |
357 | 355 | Set-StoragePool -CimSession $ClusterName -FriendlyName "S2D on $ClusterName" -FaultDomainAwarenessDefault StorageScaleUnit |
358 | 356 |
|
359 | 357 | #create new volume |
360 | | - New-Volume -CimSession $ClusterName -StoragePoolFriendlyName "S2D on $ClusterName" -FriendlyName $VolumeFriendlyName -Size 1TB -ProvisioningType Thin |
| 358 | + New-Volume -CimSession $ClusterName -StoragePoolFriendlyName "S2D on $ClusterName" -FriendlyName $VolumeFriendlyName -Size $VolumeSize -ProvisioningType Thin |
361 | 359 |
|
362 | 360 | #validate volume fault domain awareness |
363 | 361 | Get-VirtualDisk -CimSession $ClusterName | Select-Object FriendlyName,FaultDomainAwareness |
|
370 | 368 | #delete performance history including volume (without invoking it returned error "get-srpartnership : The WS-Management service cannot process the request. The CIM namespace") |
371 | 369 | Invoke-Command -ComputerName $CLusterName -ScriptBlock {Stop-ClusterPerformanceHistory -DeleteHistory} |
372 | 370 | #recreate performance history |
373 | | - Start-ClusterPerformanceHistory -cimsession $ClusterName |
| 371 | + Start-ClusterPerformanceHistory -CimSession $ClusterName |
374 | 372 |
|
375 | 373 | #validate volume fault domain awareness again (takes some time to recreate volume) |
376 | 374 | Get-VirtualDisk -CimSession $ClusterName | Select-Object FriendlyName,FaultDomainAwareness |
|
393 | 391 | #region expand cluster (2node->3node, or more) |
394 | 392 | #region install roles and features on third node |
395 | 393 | #Config |
396 | | - $Servers="Exp3" |
| 394 | + $Servers="Exp3"#,"Exp4" |
397 | 395 | # Install features on server(s) |
398 | 396 | Invoke-Command -computername $Servers -ScriptBlock { |
399 | 397 | Enable-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online -NoRestart |
|
413 | 411 | #region configure networking (assuming scalable, converged networking). |
414 | 412 | #Direct connectivity would be bit different, but since we will add 3rd node and simulating direct connectivity in MSLab would add another layer of complexity, I decided to demonstrate converged |
415 | 413 | #Config |
416 | | - $Servers="Exp3" |
| 414 | + $Servers="Exp3"#,"Exp4" |
417 | 415 | $ClusterName="Exp-Cluster" |
418 | 416 | $vSwitchName="vSwitch" |
419 | 417 | $IP=3 #start IP |
|
527 | 525 | #region add cluster member(s) |
528 | 526 | #Config |
529 | 527 | $ClusterName="Exp-Cluster" |
530 | | - $ClusterNodeNames="Exp3" |
| 528 | + $ClusterNodeNames="Exp3"#,"Exp4" |
531 | 529 | #add node |
532 | 530 | Add-ClusterNode -Name $ClusterNodeNames -Cluster $ClusterName |
533 | 531 | #endregion |
534 | 532 |
|
535 | | - #region configure ResiliencySettingNameDefault to have 3 data copies and create 3 way mirror volume |
| 533 | + #region configure ResiliencySettingNameDefault to have 3 data copies and create 3-way mirror volume |
536 | 534 | #config |
537 | 535 | $ClusterName="Exp-Cluster" |
538 | 536 | $VolumeFriendlyName="Three+NodesMirror" |
| 537 | + $VolumeSize=1TB |
539 | 538 |
|
540 | 539 | #check configuration of mirror resiliency setting (notice 2 data copies) |
541 | 540 | Get-StoragePool -CimSession $ClusterName -FriendlyName "S2D on $ClusterName" | get-resiliencysetting |
|
547 | 546 | Get-StoragePool -CimSession $ClusterName -FriendlyName "S2D on $ClusterName" | get-resiliencysetting -Name Mirror |
548 | 547 |
|
549 | 548 | #create new volume |
550 | | - New-Volume -CimSession $ClusterName -StoragePoolFriendlyName "S2D on $ClusterName" -FriendlyName $VolumeFriendlyName -Size 1TB -ProvisioningType Thin |
| 549 | + New-Volume -CimSession $ClusterName -StoragePoolFriendlyName "S2D on $ClusterName" -FriendlyName $VolumeFriendlyName -Size $VolumeSize -ProvisioningType Thin |
551 | 550 |
|
552 | 551 | #validate volume resiliency |
553 | 552 | Get-VirtualDisk -CimSession $ClusterName | Select-Object FriendlyName,NumberOfDataCopies |
|
560 | 559 | #delete performance history including volume (without invoking it returned error "get-srpartnership : The WS-Management service cannot process the request. The CIM namespace") |
561 | 560 | Invoke-Command -ComputerName $CLusterName -ScriptBlock {Stop-ClusterPerformanceHistory -DeleteHistory} |
562 | 561 | #recreate performance history |
563 | | - Start-ClusterPerformanceHistory -cimsession $ClusterName |
| 562 | + Start-ClusterPerformanceHistory -CimSession $ClusterName |
564 | 563 |
|
565 | 564 | #validate volume resiliency again (takes some time to recreate volume) |
566 | 565 | Get-VirtualDisk -CimSession $ClusterName | Select-Object FriendlyName,NumberOfDataCopies |
|
0 commit comments