Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$hv_name = $args[0]
$hv = Get-VMHost -Name $hv_name
if ($hv.ConnectionState -ne "Maintenance") {
"Not in Maintenance Mode."
exit 1
"Get ESXi Short Name"
$hv_short_name = $hv.Name -replace "\..*",""
"Get ESXi IP 4th Octet Number"
$hv_ip_4th_octet = [int]($hv_short_name.Split("-")[2]) + 200
"Set Domain"
$hv | Get-VMHostNetwork | Set-VMHostNetwork -DomainName ""
"Disable Core Dump Warning"
$hv | Get-AdvancedSetting -Name UserVars.SuppressCoredumpWarning | Set-AdvancedSetting -Value 1 -Confirm:$false
"Disable Shell Warning"
$hv | Get-AdvancedSetting -Name UserVars.SuppressShellWarning | Set-AdvancedSetting -Value 1 -Confirm:$false
"Disable KB55636 Warning"
$hv | Get-AdvancedSetting -Name UserVars.SuppressHyperthreadWarning | Set-AdvancedSetting -Value 1 -Confirm:$false
"Set NTP Servers"
$hv | Add-VMHostNtpServer -NtpServer,
$hv | Get-VMHostService | where {$_.key -eq "ntpd"} | Set-VMHostService -Policy On
$hv | Get-VMHostService | where {$_.key -eq "ntpd"} | Start-VMHostService
"Start SSH"
$hv | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy on
$hv | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService
"Start ESxi Shell"
$hv | Get-VMHostService | where {$_.key -eq "TSM"} | Set-VMHostService -Policy on
$hv | Get-VMHostService | where {$_.key -eq "TSM"} | Start-VMHostService
$pnic = $hv | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$vmk_port = $hv | Get-VMHostNetworkAdapter -VMKernel -Name vmk0
$vds = Get-VDSwitch -Name "infra-vds-01"
$dvpg = Get-VDPortgroup -VDSwitch $vds -Name "dvpg-0000-mgmt"
Add-VDSwitchVMHost -VDSwitch $vds -VMHost $hv
Add-VDSwitchPhysicalNetworkAdapter -DistributedSwitch $vds -VMHostPhysicalNic $pnic -VMHostVirtualNic $vmk_port -VirtualNicPortgroup $dvpg -Confirm:$false
$dvpg_nfs = Get-VDPortgroup -VDSwitch $vds -Name "dvpg-0051-nfs"
$dvpg_vsan = Get-VDPortgroup -VDSwitch $vds -Name "dvpg-0052-vsan"
"Add vmk1 - NFS"
$vmk1_ip = "192.168.51." + $hv_ip_4th_octet
$hv | New-VMHostNetworkAdapter -VirtualSwitch $vds -PortGroup $dvpg_nfs `
-IP $vmk1_ip -SubnetMask ""
"Add vmk2 - vSAN"
$vmk2_ip = "192.168.52." + $hv_ip_4th_octet
$hv | New-VMHostNetworkAdapter -VirtualSwitch $vds -PortGroup $dvpg_vsan `
-IP $vmk2_ip -SubnetMask "" -VsanTrafficEnabled:$true
"Enable vMotion"
$hv | Get-VMHostNetworkAdapter -Name vmk0 | Set-VMHostNetworkAdapter -VMotionEnabled:$true -Confirm:$false
"Mount NFS Datastore"
$hv | New-Datastore -Name "ds-nfs-repo-01" -Nfs -NfsHost "" -Path "/nfs/fs01"
"Set Local Syslog Directory"
$hv_logdir = "[ds-nfs-repo-01] logs/$hv_short_name"
$hv | Get-AdvancedSetting -Name | Set-AdvancedSetting -Value $hv_logdir -Confirm:$false
Copy link

gowatana commented Sep 29, 2021


自宅ラボ 2021年09月の様子。


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment