/
VCF Prep Script.ps1
76 lines (60 loc) · 3.39 KB
/
VCF Prep Script.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
#####################################
# VCF Host Prep Script #
# #
# Note: this assumes you have #
# already assigned DNS entries and #
# management IPs to the host and #
# the hosts are connected to the #
# network and are accessible. #
# #
# ***Change the variables below #
# your specific settings!*** #
#####################################
$pass = "VMware1!"
$hostfile = "C:\VCFHosts.txt"
$ntpone = "time1.domain.com"
$ntptwo = "time2.domain.com"
$dnsone = "8.8.8.8"
$dnstwo = "8.8.4.4"
$domainname = "domain.com"
#DO NOT CHANGE BELOW THIS LINE#
$hosts = Get-Content -Path $hostfile
ForEach ($esx in $hosts) {
Write-Host "Connecting to $esx" -ForegroundColor Green
Connect-VIServer -Server $esx -User root -Password $pass
Write-Host "Configuring VM Network to VLAN $vlan on $esx" -ForegroundColor Green
$vlan = Get-VirtualPortGroup -Name "Management Network"
Get-VirtualPortGroup -Name "VM Network" | Set-VirtualPortgroup -VLanID $vlan.VLanId
Write-Host "Configuring DNS and Domain Name on $esx" -ForegroundColor Green
Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domainname -DNSAddress $dnsone , $dnstwo -Confirm:$false
Write-Host "Enabling SSH on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "TSM-SSH"} | Start-VMHostService -Confirm:$false
Write-Host "Suppressing Shell Warning on $esx" -ForegroundColor Green
Get-VMHost | Get-AdvancedSetting UserVars.SuppressShellWarning | Set-AdvancedSetting -Value 1 -Confirm:$false
Write-Host "Configuring SSH Client Policy on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where {$_.Key -eq "TSM-SSH"} | Set-VMHostService -policy "on" -Confirm:$false
Write-Host "Collecting NTP Servers on $esx" -ForegroundColor Green
$allNTPList = Get-VMHostNtpServer -VMHost $esx
if ($allNTPList -contains $ntpone -AND $allntplist -contains $ntptwo) {
Write-Host "NTP Server $ntpone and $ntptwo already exist on $esx" -ForegroundColor Green
}
elseif ($ntpone -notin $allNTPList -AND $allntplist -contains $ntptwo) {
Write-Host "Adding NTP Server $ntpone on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntpone -VMHost $esx -Confirm:$false
}
elseif ($ntptwo -notin $allNTPList -AND $allntplist -contains $ntpone) {
Write-Host "Adding NTP Server $ntptwo on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntptwo -VMHost $esx -Confirm:$false
}
else {
Write-Host "Adding NTP Server $ntpone on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntpone -VMHost $esx -Confirm:$false
Write-Host "Adding NTP Server $ntptwo on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntptwo -VMHost $esx -Confirm:$false
}
Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false
Write-Host "Restarting NTP Client on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false
Write-Host "$esx Done!" -ForegroundColor Green
}