Guest User

Untitled

a guest
May 16th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.29 KB | None | 0 0
  1. # Physical ESXi host or vCenter Server to deploy vSphere 6.5 lab
  2. $VIServer = "192.168.1.220"
  3. $VIUsername = "root"
  4. $VIPassword = "VMware1!"
  5.  
  6. # Specifies whether deployment is to an ESXi host or vCenter Server
  7. # Use either ESXI or VCENTER
  8. $DeploymentTarget = "ESXI"
  9.  
  10. # Full Path to both the Nested ESXi 6.5 VA + extracted VCSA 6.5 ISO
  11. #$NestedESXiApplianceOVA = "C:\ESXI\Nested_ESXi6.5d_Appliance_Template_v1.0.ova"
  12. $NestedESXiApplianceOVA = "C:\ESXI\Nested_ESXi6.5d_Appliance_Template_v1.0\Nested_ESXi6.5d_Appliance_Template_v1.0.ovf"
  13. $VCSAInstallerPath = "C:\ESXI\VMware-VCSA-all-6.5.0-7119157"
  14.  
  15. # Nested ESXi VMs to deploy
  16. $NestedESXiHostnameToIPs = @{
  17. "HL2-DC1-ESXI-01" = "192.168.1.150"
  18. "HL2-DC1-ESXI-02" = "192.168.1.151"
  19. "HL2-DC1-ESXI-03" = "192.168.1.152"
  20. }
  21.  
  22. #Nested ESXi Bootstrap Node
  23. $bootStrapNode = "192.168.1.150"
  24.  
  25. # Nested ESXi VM Resources
  26. $NestedESXivCPU = "8"
  27. $NestedESXivMEM = "32" #GB
  28. $NestedESXiCachingvDisk = "16" #GB
  29. $NestedESXiCapacityvDisk = "200" #GB
  30.  
  31. # VCSA Deployment Configuration
  32. $VCSADeploymentSize = "tiny"
  33. $VCSADisplayName = "HL2-DC1-VCSA-01"
  34. $VCSAIPAddress = "192.168.1.160"
  35. $VCSAHostname = "192.168.1.160" #Change to IP if you don't have valid DNS
  36. $VCSAPrefix = "24"
  37. $VCSASSODomainName = "foobar99.local"
  38. $VCSASSOSiteName = "foobar99site"
  39. $VCSASSOPassword = "VMware1!"
  40. $VCSARootPassword = "VMware1!"
  41. $VCSASSHEnable = "true"
  42.  
  43. # General Deployment Configuration for both Nested ESXi VMs + VCSA
  44. $VMNetwork = "VM Network"
  45. $VMDatastore = "SSD_NVME_2TB_SAMSUNG_960PRO"
  46. $VMNetmask = "255.255.255.0"
  47. $VMGateway = "192.168.1.1"
  48. $VMDNS = "192.168.1.1"
  49. $VMNTP = "pool.ntp.org"
  50. $VMPassword = "vmware123"
  51. $VMDomain = "foobar99.local"
  52. $VMSyslog = "192.168.1.160"
  53. # Applicable to Nested ESXi only
  54. $VMSSH = "true"
  55. $VMVMFS = "false"
  56. # Applicable to VC Deployment Target only
  57. $VMCluster = "CluserNameHere"
  58.  
  59. # Name of new vSphere Datacenter/Cluster when VCSA is deployed
  60. $NewVCDatacenterName = "NADC"
  61. $NewVCVSANClusterName = "VSAN-Cluster"
  62.  
  63. #### DO NOT EDIT BEYOND HERE ####
  64.  
  65. $verboseLogFile = "vsphere65-foobar99-lab-deployment.log"
  66. $vSphereVersion = "6.5"
  67. $deploymentType = "Self Managed"
  68. $random_string = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
  69. $VAppName = "FooBar99Lab-$vSphereVersion-$random_string"
  70.  
  71. $preCheck = 1
  72. $confirmDeployment = 1
  73. $deployNestedESXiVMs = 1
  74. $bootStrapFirstNestedESXiVM = 1
  75. $deployVCSA = 1
  76. $setupNewVC = 1
  77. $addESXiHostsToVC = 1
  78. $configureVSANDiskGroups = 1
  79. $clearVSANHealthCheckAlarm = 1
  80. $moveVMsIntovApp = 1
  81.  
  82. $StartTime = Get-Date
  83.  
  84. Function My-Logger {
  85. param(
  86. [Parameter(Mandatory=$true)]
  87. [String]$message
  88. )
  89.  
  90. $timeStamp = Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
  91.  
  92. Write-Host -NoNewline -ForegroundColor White "[$timestamp]"
  93. Write-Host -ForegroundColor Green " $message"
  94. $logMessage = "[$timeStamp] $message"
  95. $logMessage | Out-File -Append -LiteralPath $verboseLogFile
  96. }
  97.  
  98. if($preCheck -eq 1) {
  99. if(!(Test-Path $NestedESXiApplianceOVA)) {
  100. Write-Host -ForegroundColor Red "`nUnable to find $NestedESXiApplianceOVA ...`nexiting"
  101. exit
  102. }
  103.  
  104. if(!(Test-Path $VCSAInstallerPath)) {
  105. Write-Host -ForegroundColor Red "`nUnable to find $VCSAInstallerPath ...`nexiting"
  106. exit
  107. }
  108. }
  109.  
  110. if($confirmDeployment -eq 1) {
  111. Write-Host -ForegroundColor Magenta "`nPlease confirm the following configuration will be deployed:`n"
  112.  
  113. Write-Host -ForegroundColor Yellow "---- vGhetto vSphere Automated Lab Deployment Configuration ---- "
  114. Write-Host -NoNewline -ForegroundColor Green "Deployment Target: "
  115. Write-Host -ForegroundColor White $DeploymentTarget
  116. Write-Host -NoNewline -ForegroundColor Green "Deployment Type: "
  117. Write-Host -ForegroundColor White $deploymentType
  118. Write-Host -NoNewline -ForegroundColor Green "vSphere Version: "
  119. Write-Host -ForegroundColor White "vSphere $vSphereVersion"
  120. Write-Host -NoNewline -ForegroundColor Green "Nested ESXi Image Path: "
  121. Write-Host -ForegroundColor White $NestedESXiApplianceOVA
  122. Write-Host -NoNewline -ForegroundColor Green "VCSA Image Path: "
  123. Write-Host -ForegroundColor White $VCSAInstallerPath
  124.  
  125. if($DeploymentTarget -eq "ESXI") {
  126. Write-Host -ForegroundColor Yellow "`n---- Physical ESXi Configuration ----"
  127. Write-Host -NoNewline -ForegroundColor Green "ESXi Address: "
  128. } else {
  129. Write-Host -ForegroundColor Yellow "`n---- vCenter Server Configuration ----"
  130. Write-Host -NoNewline -ForegroundColor Green "vCenter Server Address: "
  131. }
  132.  
  133. Write-Host -ForegroundColor White $VIServer
  134. Write-Host -NoNewline -ForegroundColor Green "Username: "
  135. Write-Host -ForegroundColor White $VIUsername
  136. Write-Host -NoNewline -ForegroundColor Green "VM Network: "
  137. Write-Host -ForegroundColor White $VMNetwork
  138. Write-Host -NoNewline -ForegroundColor Green "VM Storage: "
  139. Write-Host -ForegroundColor White $VMDatastore
  140.  
  141. if($DeploymentTarget -eq "VCENTER") {
  142. Write-Host -NoNewline -ForegroundColor Green "VM Cluster: "
  143. Write-Host -ForegroundColor White $VMCluster
  144. Write-Host -NoNewline -ForegroundColor Green "VM vApp: "
  145. Write-Host -ForegroundColor White $VAppName
  146. }
  147.  
  148. Write-Host -ForegroundColor Yellow "`n---- vESXi Configuration ----"
  149. Write-Host -NoNewline -ForegroundColor Green "# of Nested ESXi VMs: "
  150. Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.count
  151. Write-Host -NoNewline -ForegroundColor Green "vCPU: "
  152. Write-Host -ForegroundColor White $NestedESXivCPU
  153. Write-Host -NoNewline -ForegroundColor Green "vMEM: "
  154. Write-Host -ForegroundColor White "$NestedESXivMEM GB"
  155. Write-Host -NoNewline -ForegroundColor Green "Caching VMDK: "
  156. Write-Host -ForegroundColor White "$NestedESXiCachingvDisk GB"
  157. Write-Host -NoNewline -ForegroundColor Green "Capacity VMDK: "
  158. Write-Host -ForegroundColor White "$NestedESXiCapacityvDisk GB"
  159. Write-Host -NoNewline -ForegroundColor Green "IP Address(s): "
  160. Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.Values
  161. Write-Host -NoNewline -ForegroundColor Green "Netmask "
  162. Write-Host -ForegroundColor White $VMNetmask
  163. Write-Host -NoNewline -ForegroundColor Green "Gateway: "
  164. Write-Host -ForegroundColor White $VMGateway
  165. Write-Host -NoNewline -ForegroundColor Green "DNS: "
  166. Write-Host -ForegroundColor White $VMDNS
  167. Write-Host -NoNewline -ForegroundColor Green "NTP: "
  168. Write-Host -ForegroundColor White $VMNTP
  169. Write-Host -NoNewline -ForegroundColor Green "Syslog: "
  170. Write-Host -ForegroundColor White $VMSyslog
  171. Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
  172. Write-Host -ForegroundColor White $VMSSH
  173. Write-Host -NoNewline -ForegroundColor Green "Create VMFS Volume: "
  174. Write-Host -ForegroundColor White $VMVMFS
  175. Write-Host -NoNewline -ForegroundColor Green "Root Password: "
  176. Write-Host -ForegroundColor White $VMPassword
  177. Write-Host -NoNewline -ForegroundColor Green "Bootstrap ESXi Node: "
  178. Write-Host -ForegroundColor White $bootStrapNode
  179.  
  180. Write-Host -ForegroundColor Yellow "`n---- VCSA Configuration ----"
  181. Write-Host -NoNewline -ForegroundColor Green "Deployment Size: "
  182. Write-Host -ForegroundColor White $VCSADeploymentSize
  183. Write-Host -NoNewline -ForegroundColor Green "SSO Domain: "
  184. Write-Host -ForegroundColor White $VCSASSODomainName
  185. Write-Host -NoNewline -ForegroundColor Green "SSO Site: "
  186. Write-Host -ForegroundColor White $VCSASSOSiteName
  187. Write-Host -NoNewline -ForegroundColor Green "SSO Password: "
  188. Write-Host -ForegroundColor White $VCSASSOPassword
  189. Write-Host -NoNewline -ForegroundColor Green "Root Password: "
  190. Write-Host -ForegroundColor White $VCSARootPassword
  191. Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
  192. Write-Host -ForegroundColor White $VCSASSHEnable
  193. Write-Host -NoNewline -ForegroundColor Green "Hostname: "
  194. Write-Host -ForegroundColor White $VCSAHostname
  195. Write-Host -NoNewline -ForegroundColor Green "IP Address: "
  196. Write-Host -ForegroundColor White $VCSAIPAddress
  197. Write-Host -NoNewline -ForegroundColor Green "Netmask "
  198. Write-Host -ForegroundColor White $VMNetmask
  199. Write-Host -NoNewline -ForegroundColor Green "Gateway: "
  200. Write-Host -ForegroundColor White $VMGateway
  201.  
  202. Write-Host -ForegroundColor Magenta "`nWould you like to proceed with this deployment?`n"
  203. $answer = Read-Host -Prompt "Do you accept (Y or N)"
  204. if($answer -ne "Y" -or $answer -ne "y") {
  205. exit
  206. }
  207. Clear-Host
  208. }
  209.  
  210. if($deployNestedESXiVMs -eq 1) {
  211. My-Logger "Connecting to $VIServer ..."
  212. $viConnection = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue
  213.  
  214. if($DeploymentTarget -eq "ESXI") {
  215. $datastore = Get-Datastore -Server $viConnection -Name $VMDatastore
  216. $vmhost = Get-VMHost -Server $viConnection
  217. $network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork -VMHost $vmhost
  218.  
  219. if($datastore.Type -eq "vsan") {
  220. My-Logger "VSAN Datastore detected, enabling Fake SCSI Reservations ..."
  221. Get-AdvancedSetting -Entity $vmhost -Name "VSAN.FakeSCSIReservations" | Set-AdvancedSetting -Value 1 -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  222. }
  223. } else {
  224. $datastore = Get-Datastore -Server $viConnection -Name $VMDatastore | Select -First 1
  225. $network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork | Select -First 1
  226. $cluster = Get-Cluster -Server $viConnection -Name $VMCluster
  227. $datacenter = $cluster | Get-Datacenter
  228. $vmhost = $cluster | Get-VMHost | Select -First 1
  229. }
  230.  
  231. if($DeploymentTarget -eq "ESXI") {
  232. $NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
  233. $VMName = $_.Key
  234. $VMIPAddress = $_.Value
  235.  
  236. My-Logger "Deploying Nested ESXi VM $VMName ..."
  237. $vm = Import-VApp -Server $viConnection -Source $NestedESXiApplianceOVA -Name $VMName -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
  238.  
  239. My-Logger "Updating VM Network ..."
  240. foreach($networkAdapter in ($vm | Get-NetworkAdapter))
  241. {
  242. My-Logger "Configuring adapter $networkAdapter in $vm"
  243. $networkAdapter | Set-NetworkAdapter -Portgroup $network -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  244. sleep 5
  245. }
  246.  
  247. My-Logger "Updating vCPU Count to $NestedESXivCPU & vMEM to $NestedESXivMEM GB ..."
  248. Set-VM -Server $viConnection -VM $vm -NumCpu $NestedESXivCPU -MemoryGB $NestedESXivMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  249.  
  250. My-Logger "Updating vSAN Caching VMDK size to $NestedESXiCachingvDisk GB ..."
  251. Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  252.  
  253. My-Logger "Updating vSAN Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
  254. Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 3" | Set-HardDisk -CapacityGB $NestedESXiCapacityvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  255.  
  256. $orignalExtraConfig = $vm.ExtensionData.Config.ExtraConfig
  257. $a = New-Object VMware.Vim.OptionValue
  258. $a.key = "guestinfo.hostname"
  259. $a.value = $VMName
  260. $b = New-Object VMware.Vim.OptionValue
  261. $b.key = "guestinfo.ipaddress"
  262. $b.value = $VMIPAddress
  263. $c = New-Object VMware.Vim.OptionValue
  264. $c.key = "guestinfo.netmask"
  265. $c.value = $VMNetmask
  266. $d = New-Object VMware.Vim.OptionValue
  267. $d.key = "guestinfo.gateway"
  268. $d.value = $VMGateway
  269. $e = New-Object VMware.Vim.OptionValue
  270. $e.key = "guestinfo.dns"
  271. $e.value = $VMDNS
  272. $f = New-Object VMware.Vim.OptionValue
  273. $f.key = "guestinfo.domain"
  274. $f.value = $VMDomain
  275. $g = New-Object VMware.Vim.OptionValue
  276. $g.key = "guestinfo.ntp"
  277. $g.value = $VMNTP
  278. $h = New-Object VMware.Vim.OptionValue
  279. $h.key = "guestinfo.syslog"
  280. $h.value = $VMSyslog
  281. $i = New-Object VMware.Vim.OptionValue
  282. $i.key = "guestinfo.password"
  283. $i.value = $VMPassword
  284. $j = New-Object VMware.Vim.OptionValue
  285. $j.key = "guestinfo.ssh"
  286. $j.value = $VMSSH
  287. $k = New-Object VMware.Vim.OptionValue
  288. $k.key = "guestinfo.createvmfs"
  289. $k.value = $VMVMFS
  290. $l = New-Object VMware.Vim.OptionValue
  291. $l.key = "ethernet1.filter4.name"
  292. $l.value = "dvfilter-maclearn"
  293. $m = New-Object VMware.Vim.OptionValue
  294. $m.key = "ethernet1.filter4.onFailure"
  295. $m.value = "failOpen"
  296. $orignalExtraConfig+=$a
  297. $orignalExtraConfig+=$b
  298. $orignalExtraConfig+=$c
  299. $orignalExtraConfig+=$d
  300. $orignalExtraConfig+=$e
  301. $orignalExtraConfig+=$f
  302. $orignalExtraConfig+=$g
  303. $orignalExtraConfig+=$h
  304. $orignalExtraConfig+=$i
  305. $orignalExtraConfig+=$j
  306. $orignalExtraConfig+=$k
  307. $orignalExtraConfig+=$l
  308. $orignalExtraConfig+=$m
  309.  
  310. $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
  311. $spec.ExtraConfig = $orignalExtraConfig
  312.  
  313. My-Logger "Adding guestinfo customization properties to $vmname ..."
  314. $task = $vm.ExtensionData.ReconfigVM_Task($spec)
  315. $task1 = Get-Task -Id ("Task-$($task.value)")
  316. $task1 | Wait-Task | Out-File -Append -LiteralPath $verboseLogFile
  317.  
  318. My-Logger "Powering On $vmname ..."
  319. Start-VM -Server $viConnection -VM $vm -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  320. }
  321. } else {
  322. $NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
  323. $VMName = $_.Key
  324. $VMIPAddress = $_.Value
  325.  
  326. $ovfconfig = Get-OvfConfiguration $NestedESXiApplianceOVA
  327. $ovfconfig.NetworkMapping.VM_Network.value = $VMNetwork
  328.  
  329. $ovfconfig.common.guestinfo.hostname.value = $VMName
  330. $ovfconfig.common.guestinfo.ipaddress.value = $VMIPAddress
  331. $ovfconfig.common.guestinfo.netmask.value = $VMNetmask
  332. $ovfconfig.common.guestinfo.gateway.value = $VMGateway
  333. $ovfconfig.common.guestinfo.dns.value = $VMDNS
  334. $ovfconfig.common.guestinfo.domain.value = $VMDomain
  335. $ovfconfig.common.guestinfo.ntp.value = $VMNTP
  336. $ovfconfig.common.guestinfo.syslog.value = $VMSyslog
  337. $ovfconfig.common.guestinfo.password.value = $VMPassword
  338. if($VMSSH -eq "true") {
  339. $VMSSHVar = $true
  340. } else {
  341. $VMSSHVar = $false
  342. }
  343. $ovfconfig.common.guestinfo.ssh.value = $VMSSHVar
  344.  
  345. My-Logger "Deploying Nested ESXi VM $VMName ..."
  346. $vm = Import-VApp -Source $NestedESXiApplianceOVA -OvfConfiguration $ovfconfig -Name $VMName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
  347.  
  348. # Add the dvfilter settings to the exisiting ethernet1 (not part of ova template)
  349. My-Logger "Correcting missing dvFilter settings for Ethernet[1] ..."
  350. $vm | New-AdvancedSetting -name "ethernet1.filter4.name" -value "dvfilter-maclearn" -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  351. $vm | New-AdvancedSetting -Name "ethernet1.filter4.onFailure" -value "failOpen" -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  352.  
  353. My-Logger "Updating vCPU Count to $NestedESXivCPU & vMEM to $NestedESXivMEM GB ..."
  354. Set-VM -Server $viConnection -VM $vm -NumCpu $NestedESXivCPU -MemoryGB $NestedESXivMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  355.  
  356. My-Logger "Updating vSAN Caching VMDK size to $NestedESXiCachingvDisk GB ..."
  357. Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  358.  
  359. My-Logger "Updating vSAN Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
  360. Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 3" | Set-HardDisk -CapacityGB $NestedESXiCapacityvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  361.  
  362. My-Logger "Powering On $vmname ..."
  363. $vm | Start-Vm -RunAsync | Out-Null
  364. }
  365. }
  366.  
  367. if($moveVMsIntovApp -eq 1 -and $DeploymentTarget -eq "VCENTER") {
  368. My-Logger "Creating vApp $VAppName ..."
  369. $VApp = New-VApp -Name $VAppName -Server $viConnection -Location $cluster
  370.  
  371. if($deployNestedESXiVMs -eq 1) {
  372. My-Logger "Moving Nested ESXi VMs into $VAppName vApp ..."
  373. $NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
  374. $vm = Get-VM -Name $_.Key -Server $viConnection
  375. Move-VM -VM $vm -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
  376. }
  377. }
  378. }
  379.  
  380. My-Logger "Disconnecting from $VIServer ..."
  381. Disconnect-VIServer $viConnection -Confirm:$false
  382. }
  383.  
  384. if($bootStrapFirstNestedESXiVM -eq 1) {
  385. do {
  386. My-Logger "Waiting for $bootStrapNode to be ready on network ..."
  387. $ping = test-connection $bootStrapNode -Quiet
  388. sleep 60
  389. } until ($ping -contains "True")
  390.  
  391. My-Logger "Connecting to ESXi bootstrap node ..."
  392. $vEsxi = Connect-VIServer -Server $bootStrapNode -User root -Password $VMPassword -WarningAction SilentlyContinue
  393.  
  394. My-Logger "Updating the ESXi host VSAN Policy to allow Force Provisioning ..."
  395. $esxcli = Get-EsxCli -Server $vEsxi -V2
  396. $VSANPolicy = '(("hostFailuresToTolerate" i1) ("forceProvisioning" i1))'
  397. $VSANPolicyDefaults = $esxcli.vsan.policy.setdefault.CreateArgs()
  398. $VSANPolicyDefaults.policy = $VSANPolicy
  399. $VSANPolicyDefaults.policyclass = "vdisk"
  400. $esxcli.vsan.policy.setdefault.Invoke($VSANPolicyDefaults) | Out-File -Append -LiteralPath $verboseLogFile
  401. $VSANPolicyDefaults.policyclass = "vmnamespace"
  402. $esxcli.vsan.policy.setdefault.Invoke($VSANPolicyDefaults) | Out-File -Append -LiteralPath $verboseLogFile
  403.  
  404. My-Logger "Creating a new VSAN Cluster"
  405. $esxcli.vsan.cluster.new.Invoke() | Out-File -Append -LiteralPath $verboseLogFile
  406.  
  407. $luns = Get-ScsiLun -Server $vEsxi | select CanonicalName, CapacityGB
  408.  
  409. My-Logger "Querying ESXi host disks to create VSAN Diskgroups ..."
  410. foreach ($lun in $luns) {
  411. if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCachingvDisk") {
  412. $vsanCacheDisk = $lun.CanonicalName
  413. }
  414. if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCapacityvDisk") {
  415. $vsanCapacityDisk = $lun.CanonicalName
  416. }
  417. }
  418.  
  419. My-Logger "Tagging Capacity Disk ..."
  420. $capacitytag = $esxcli.vsan.storage.tag.add.CreateArgs()
  421. $capacitytag.disk = $vsanCapacityDisk
  422. $capacitytag.tag = "capacityFlash"
  423. $esxcli.vsan.storage.tag.add.Invoke($capacitytag) | Out-File -Append -LiteralPath $verboseLogFile
  424.  
  425. My-Logger "Creating VSAN Diskgroup ..."
  426. $addvsanstorage = $esxcli.vsan.storage.add.CreateArgs()
  427. $addvsanstorage.ssd = $vsanCacheDisk
  428. $addvsanstorage.disks = $vsanCapacityDisk
  429. $esxcli.vsan.storage.add.Invoke($addvsanstorage) | Out-File -Append -LiteralPath $verboseLogFile
  430.  
  431. My-Logger "Disconnecting from $esxi ..."
  432. Disconnect-VIServer $vEsxi -Confirm:$false
  433. }
  434.  
  435. if($deployVCSA -eq 1) {
  436. My-Logger "Connecting to first ESXi bootstrap node ..."
  437. $vEsxi = Connect-VIServer -Server $bootStrapNode -User root -Password $VMPassword -WarningAction SilentlyContinue
  438.  
  439. # Deploy using the VCSA CLI Installer
  440. $config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_ESXi.json") | convertfrom-json
  441. $config.'new.vcsa'.esxi.hostname = $bootStrapNode
  442. $config.'new.vcsa'.esxi.username = "root"
  443. $config.'new.vcsa'.esxi.password = $VMPassword
  444. $config.'new.vcsa'.esxi.'deployment.network' = "VM Network"
  445. $config.'new.vcsa'.esxi.datastore = "vsanDatastore"
  446. $config.'new.vcsa'.appliance.'thin.disk.mode' = $true
  447. $config.'new.vcsa'.appliance.'deployment.option' = $VCSADeploymentSize
  448. $config.'new.vcsa'.appliance.name = $VCSADisplayName
  449. $config.'new.vcsa'.network.'ip.family' = "ipv4"
  450. $config.'new.vcsa'.network.mode = "static"
  451. $config.'new.vcsa'.network.ip = $VCSAIPAddress
  452. $config.'new.vcsa'.network.'dns.servers'[0] = $VMDNS
  453. $config.'new.vcsa'.network.prefix = $VCSAPrefix
  454. $config.'new.vcsa'.network.gateway = $VMGateway
  455. $config.'new.vcsa'.network.'system.name' = $VCSAHostname
  456. $config.'new.vcsa'.os.password = $VCSARootPassword
  457. if($VCSASSHEnable -eq "true") {
  458. $VCSASSHEnableVar = $true
  459. } else {
  460. $VCSASSHEnableVar = $false
  461. }
  462. $config.'new.vcsa'.os.'ssh.enable' = $VCSASSHEnableVar
  463. $config.'new.vcsa'.sso.password = $VCSASSOPassword
  464. $config.'new.vcsa'.sso.'domain-name' = $VCSASSODomainName
  465. $config.'new.vcsa'.sso.'site-name' = $VCSASSOSiteName
  466.  
  467. My-Logger "Creating VCSA JSON Configuration file for deployment ..."
  468. $config | ConvertTo-Json | Set-Content -Path "$($ENV:Temp)\jsontemplate.json"
  469.  
  470. My-Logger "Deploying the VCSA ..."
  471. Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:Temp)\jsontemplate.json" | Out-File -Append -LiteralPath $verboseLogFile
  472.  
  473. My-Logger "Disconnecting from $bootStrapNode ..."
  474. Disconnect-VIServer $vEsxi -Confirm:$false
  475. }
  476.  
  477. if($setupNewVC -eq 1) {
  478. My-Logger "Connecting to the new VCSA ..."
  479. $vc = Connect-VIServer $VCSAIPAddress -User "administrator@$VCSASSODomainName" -Password $VCSASSOPassword -WarningAction SilentlyContinue
  480.  
  481. My-Logger "Creating Datacenter $NewVCDatacenterName ..."
  482. New-Datacenter -Server $vc -Name $NewVCDatacenterName -Location (Get-Folder -Type Datacenter -Server $vc) | Out-File -Append -LiteralPath $verboseLogFile
  483.  
  484. My-Logger "Creating VSAN Cluster $NewVCVSANClusterName ..."
  485. New-Cluster -Server $vc -Name $NewVCVSANClusterName -Location (Get-Datacenter -Name $NewVCDatacenterName -Server $vc) -DrsEnabled -VsanEnabled -VsanDiskClaimMode 'Manual' | Out-File -Append -LiteralPath $verboseLogFile
  486.  
  487. if($addESXiHostsToVC -eq 1) {
  488. $NestedESXiHostnameToIPs.GetEnumerator() | sort -Property Value | Foreach-Object {
  489. $VMName = $_.Key
  490. $VMIPAddress = $_.Value
  491.  
  492. My-Logger "Adding ESXi host $VMIPAddress to Cluster ..."
  493. Add-VMHost -Server $vc -Location (Get-Cluster -Name $NewVCVSANClusterName) -User "root" -Password $VMPassword -Name $VMIPAddress -Force | Out-File -Append -LiteralPath $verboseLogFile
  494. }
  495.  
  496. }
  497.  
  498. if($configureVSANDiskGroups -eq 1) {
  499. My-Logger "Enabling VSAN Space Efficiency/De-Dupe & disabling VSAN Health Check ..."
  500. Get-VsanClusterConfiguration -Server $vc -Cluster $NewVCVSANClusterName | Set-VsanClusterConfiguration -SpaceEfficiencyEnabled $true -HealthCheckIntervalMinutes 0 | Out-File -Append -LiteralPath $verboseLogFile
  501.  
  502. foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
  503. if((Get-VsanDiskGroup -VMHost $vmhost) -eq $null) {
  504. $luns = $vmhost | Get-ScsiLun | select CanonicalName, CapacityGB
  505.  
  506. My-Logger "Querying ESXi host disks to create VSAN Diskgroups ..."
  507. foreach ($lun in $luns) {
  508. if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCachingvDisk") {
  509. $vsanCacheDisk = $lun.CanonicalName
  510. }
  511. if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCapacityvDisk") {
  512. $vsanCapacityDisk = $lun.CanonicalName
  513. }
  514. }
  515. My-Logger "Creating VSAN DiskGroup for $vmhost ..."
  516. New-VsanDiskGroup -Server $vc -VMHost $vmhost -SsdCanonicalName $vsanCacheDisk -DataDiskCanonicalName $vsanCapacityDisk | Out-File -Append -LiteralPath $verboseLogFile
  517. }
  518. }
  519. }
  520.  
  521. if($clearVSANHealthCheckAlarm -eq 1) {
  522. My-Logger "Clearing default VSAN Health Check Alarms, not applicable in Nested ESXi env ..."
  523. $alarmMgr = Get-View AlarmManager -Server $vc
  524. Get-Cluster -Server $vc | where {$_.ExtensionData.TriggeredAlarmState} | %{
  525. $cluster = $_
  526. $Cluster.ExtensionData.TriggeredAlarmState | %{
  527. $alarmMgr.AcknowledgeAlarm($_.Alarm,$cluster.ExtensionData.MoRef)
  528. }
  529. }
  530.  
  531. My-Logger "Updating VSAN Default VM Storage Policy back to its defaults ..."
  532. $VSANPolicy = Get-SpbmStoragePolicy "Virtual SAN Default Storage Policy"
  533. $Ruleset = New-SpbmRuleSet -Name "Rule-set 1" -AllOfRules @((New-SpbmRule -Capability VSAN.forceProvisioning $false), (New-SpbmRule -Capability VSAN.hostFailuresToTolerate 1))
  534. $VSANPolicy | Set-SpbmStoragePolicy -RuleSet $Ruleset | Out-File -Append -LiteralPath $verboseLogFile
  535. }
  536.  
  537. My-Logger "Disconnecting from new VCSA ..."
  538. Disconnect-VIServer $vc -Confirm:$false
  539. }
  540. $EndTime = Get-Date
  541. $duration = [math]::Round((New-TimeSpan -Start $StartTime -End $EndTime).TotalMinutes,2)
  542.  
  543. My-Logger "vSphere $vSphereVersion Lab Deployment Complete!"
  544. My-Logger "StartTime: $StartTime"
  545. My-Logger " EndTime: $EndTime"
  546. My-Logger " Duration: $duration minutes"
Add Comment
Please, Sign In to add comment