-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig-VSAN-ESA-VCF-Lab-Host.ps1
More file actions
101 lines (80 loc) · 4.36 KB
/
Copy pathConfig-VSAN-ESA-VCF-Lab-Host.ps1
File metadata and controls
101 lines (80 loc) · 4.36 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
Clear
# Begin Script
$vmhost_name = "vcf-w01-esx01"
$vmhost_temp_ip = "192.168.100.13" #DHCP IP
# Settings to Change per VMhost
$mgmt_vlan = "<your vlan>"
$dns_domain = "<your domain name>"
$vmhost_subnetmask = "255.255.255.0"
$ntpserver="nl.pool.ntp.org"
$dnsAddress1 = "<your primaire dns server>"
$dnsAddress2 = "<your secondary dns server>"
$vmkernelgateway = "<gateway ip adres>"
$MockFile = "D:\ISO\VCF9\nested-vsan-esa-mock-hw.vib"
$ESXCreds = Get-Credential
Connect-VIServer $vmhost_temp_ip -Credential $ESXCreds
$vmhost = "$vmhost_name.$dns_domain"
# Start Fase 1
# Disable IPv6
$esxcli = Get-EsxCli -VMHost $vmhost_temp_ip -V2
$argument = $esxcli.system.module.parameters.set.CreateArgs()
$argument.module = "tcpip4"
$argument.parameterstring = "ipv6=0"
$esxcli.system.module.parameters.set.Invoke($argument)
# Set Fixt DNS enz
$vmHostNetworkInfo = Get-VmHostNetwork -Host $vmhost_temp_ip
Set-VMHostNetwork -Network $vmHostNetworkInfo -DomainName $dns_domain -HostName $vmhost_name -DnsFromDhcp $false -DnsAddress $dnsAddress1.$dnsAddress2 -VMKernelGateway $vmkernelgateway
# DNS Name to IP
$ip = [System.Net.Dns]::GetHostaddresses($vmhost) | Select-Object IPAddressToString
$vmhost_ip = $ip.IPAddressToString
#Config VMK0
Get-VMHostNetworkAdapter -VMHost $vmhost_temp_ip -Name vmk0 | Set-VMHostNetworkAdapter -IP $vmhost_ip -SubnetMask $vmhost_subnetmask -confirm:$false | Out-Null
Disconnect-VIServer * -Confirm:$false | Out-Null
Connect-VIServer $vmhost -Credential $ESXCreds
$vmhost = Get-VMHost
# Rename local datastore
Get-VMhost $vmhost | Get-Datastore -Name datastore* | Set-Datastore -Name "$vmhost_name-datastore"
# NTP
Add-VmHostNtpServer -NtpServer $ntpserver -vmhost $vmhost
#Start NTP client service and set to automatic
Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "on"
Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService -Confirm:$false
# === VIB Deployment & vsanmgmtd Restart ===
$esxDatastore = "${vmhost_name}-datastore"
$vmstorePath = "vmstores:\$vmhost@443\ha-datacenter\$esxDatastore"
$vibPath = "/vmfs/volumes/$esxDatastore/nested-vsan-esa-mock-hw.vib"
Write-Host "Connecting to $vmhost for VIB installation..." -ForegroundColor Cyan
try {
$esxcli = Get-EsxCli -VMHost $vmhost -V2
Write-Host "Uploading '$MockFile' to $vmstorePath ..."
Copy-DatastoreItem -Item $MockFile -Destination $vmstorePath -Force -ErrorAction Stop
Write-Host "Setting acceptance level to CommunitySupported ..."
$esxcli.software.acceptance.set.Invoke(@{ level = "CommunitySupported" })
Write-Host "Installing VIB ..."
$installParams = @{ viburl = $vibPath; nosigcheck = $true }
$result = $esxcli.software.vib.install.Invoke($installParams)
Write-Host "✅ VIB installation result: $($result.Message)" -ForegroundColor Green
} catch {
Write-Host "❌ EsxCLI operations failed on $VMName ($vmhost): $_" -ForegroundColor Red
}
try {
# Generate new certificate on the ESXi host
$vmhost | Get-VMHostService | Where-Object {$_.Key -eq "TSM-SSH"} | Start-VMHostService
$session = New-SSHSession -ComputerName $vmHost -Credential $ESXCreds -Force -AcceptKey:$true
$GenerateCertCommand = "/sbin/generate-certificates"
Invoke-SSHCommand -SSHSession $session -Command $GenerateCertCommand
# vSAN Cluster Compliance # https://knowledge.broadcom.com/external/article/372309/workaround-to-reduce-impact-of-resync-tr.html
# esxcfg-advcfg -s 1 /VSAN/DOMNetworkSchedulerThrottleComponent
$vSANClusterCompliance = "esxcli system settings advanced set -i 1 -o /VSAN/DOMNetworkSchedulerThrottleComponent"
Invoke-SSHCommand -SSHSession $session -Command $vSANClusterCompliance
$restartCommand = "/etc/init.d/hostd restart && /etc/init.d/vpxa restart"
Invoke-SSHCommand -SSHSession $session -Command $restartCommand
$hostrestart="reboot"
Invoke-SSHCommand -SSHSession $session -Command $hostrestart
Remove-SSHSession -SSHSession $session
Write-Host "✅ New Selfsigned Certificate is generated on $vmHost" -ForegroundColor Green
} catch {
Write-Host "❌ Selfsigned Certificate is NOT generated on $vmHost" -ForegroundColor Red
}
# Disconnect-ViCenter
Disconnect-VIServer * -Confirm:$false | Out-Null