Do to the nature of my job I deal with multiple individual esx hosts. They are nt part of vcenter cluster. The script below works....somewhat.....NTP section is fine.....It is the portgroup section....it will apply the tags to the first host portgroup..then red inks and gives me a time out error.....I have tried to pipe portgroup commands to a start-stop to delay the tagging but it didnt except....any help would be appreciated. This script is in first draft phase and I am just trying to get portgroups to tag on multiple hosts with exact same configuration.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Hello #
# #
# You will choose What Config you want to use #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Write-Host -ForegroundColor DarkRed -BackgroundColor white "Welcome To Nutanix ESX Config Script"
# # # # # # # # # # # # # # # # #
# Setting Variables for Loop #
# # # # # # # # # # # # # # # # #
$root = "root"
$pwd = "password"
$tag = "408"
$a = "x.x.x.x"
$b = "x.x.x.x"
$c= "x.x.x.x"
$esxlist = $a , $b , $c
$ntp1 = "x.x.x.x"
$ntp2 = "x.x.x.x"
$ntp3 = "x.x.x.x"
$ntp4 = "x.x.x.x"
######Begin Loop###########
foreach($esx in $esxlist) {
###########################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "Choose a Configuration type Sir"
# # # # # # # # # # # # # # # # #
# Setting Variable for Switch #
# # # # # # # # # # # # # # # # #
$VmwareConfig = ""
Write-Host -ForegroundColor Green -BackgroundColor Black `
@"
1 = Configure NTP/Portgroup
2 = Configure NTP
3 = Configure Portgroup
"@; [int]$choicetype = Read-Host
switch ($choicetype)
{
# # # # # # # # # # # # # # #
# Configure NTP/Portgroup #
# # # # # # # # # # # # # # #
1 {$VmwareConfig = `
Connect-VIServer -Server $esx -User $root -Password $pwd
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
Write-Host -foregroundColor DarkGreen -BackgroundColor white "Please enter NTP Server Info"
###########Ensure Firewall Policy is Configured#####################################################################
Get-VMHostFirewallException -VMHost $esx | ? {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true
####################################################################################################################
######Add NTP Servers###########################################
Add-VMHostNtpServer -NtpServer $ntp1 , $ntp2 , $ntp3 , $ntp4 -VMHost $esx
################################################################
############Start NTP Service###############################################
Get-VmHostService -VMHost $esx | ?{$_.key -eq "ntpd"} | Start-VMHostService
############################################################################
#############Ensure service is set to start/stop on host#################################################
Get-VmHostService -VMHost $esx | ? {$_.key -eq "ntpd"} | Set-VMHostService -policy "on"
#########################################################################################################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "NTP Config Complete, now lets configure the Portgroups to your desired specification"
Write-Host -foregroundColor DarkGreen -BackgroundColor white " Tagging CVM Port Group"
#############Tagging CVM###################################################
Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "VM Network" | Set-VirtualPortGroup -VLanId $tag
###########################################################################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "Tagging Host"
##########Tag Management Portgroup#################################################
Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "Management Network" | Set-VirtualPortGroup -VLanId $tag
###################################################################################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "End Transmission"
}
# # # # # # # # # # # # #
# Set NTP ServerS #
# # # # # # # # # # # # #
2 {$VmwareConfig = `
######Begin Loop###########
foreach($esx in $esxlist) {
Connect-VIServer -Server $esx -User $root -Password $pwd
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
Write-Host -foregroundColor DarkGreen -BackgroundColor white "Please enter NTP Server Info"
###########Ensure Firewall Policy is Configured#####################################################################
Get-VMHostFirewallException -VMHost $esx | ? {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true
####################################################################################################################
######Add NTP Servers###########################################
Add-VMHostNtpServer -NtpServer $ntp -VMHost $esx
################################################################
############Start NTP Service###############################################
Get-VmHostService -VMHost $esx | ?{$_.key -eq "ntpd"} | Start-VMHostService
############################################################################
#############Ensure service is set to start/stop on host#################################################
Get-VmHostService -VMHost $esx | ? {$_.key -eq "ntpd"} | Set-VMHostService -policy "on"
}
# # # # # # # # # # # # # # #
# Configure Portgroups #
# # # # # # # # # # # # # # #
3 {$VmwareConfig = `
#########loggging into each host################
Connect-VIServer -Server $esx -User $root -Password $pwd
################################################
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
Write-Host -foregroundColor DarkGreen -BackgroundColor white " Tagging CVM Port Group"
#############Tagging CVM###################################################
Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "VM Network" | Set-VirtualPortGroup -VLanId $tag
###########################################################################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "Tagging Host"
##########Tag Management Portgroup#################################################
Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "Management Network" | Set-VirtualPortGroup -VLanId $tag
###################################################################################
Write-Host -foregroundColor DarkGreen -BackgroundColor white "End Transmission"
}
}
}