Last month I’ve wrote a script for a company that is merging with a new company in a different datacenter, that means new ip-addresses, new subnet, new gateway, new DNS servers and rejoin vCenter server.. my part was to migrate all (60) VMware vSphere hosts to the new subnet and rejoin the vSphere vCenter cluster… without downtime!
Function:
#Connect to vCenter server
– Specify host
– Enter Host Standby mode
– Move all VM’s to other hosts in cluster
– Re-balance with DRS
– Disconnect host
– Remove host from cluster
#Connect to ESXi Server
– Add new VMKernel Management Network with new range in vSwitch0
– Enable Management option for new VMkernel
– Configure NIC Teaming policy
– Configure new DNS servers
– Configure new VMkernel gateway
– Reboot host
#MANUAL ACTION: Update DNS records at configured DNS servers
#Connect to vCenter server
– Add new record in vCenter server host file with new host ipaddress Management VMkernel
– Add host with new VMkernel Management Network
– Delete old VMkernel from vSwitch0
– Exit Host Standby mode
– Rebalance cluster with DRS
#Script finished
– Next host…>
The script:
#====================================================================#
# SCRIPT: VMware_vSphere_IP_Redesign_v.1.0.ps1 #
# AUTHOR: S.Daems - VMpros.nl #
# CREATED: 22/01/2012 #
# MODIFIED: 30/01/2012 #
# VERSION: v.1.0 #
# #
#====================================================================#
# CHANGELOG: #
# #
# v.1.0 #
# - Script created #
# #
#====================================================================#
# FUNCTION: #
# #
# #Connect to vCenter server #
# Specify host #
# Enter Host Standby mode #
# Move all VM's to other hosts in cluster #
# Re-balance with DRS #
# Disconnect host #
# Remove host from cluster #
# #
# #Connect to ESXi Server #
# Add new VMKernel Management Network with new range in vSwitch0 #
# Enable Management option for new VMkernel #
# Configure NIC Teaming policy #
# Configure new DNS servers #
# Configure new VMkernel gateway #
# Reboot host #
# #
# #MANUAL ACTION: Update DNS records at configured DNS servers #
# #
# #Connect to vCenter server #
# Add new record in vCenter server host file with new host ip- #
# address Management VMkernel #
# Add host with new VMkernel Management Network #
# Delete old VMkernel from vSwitch0 #
# Exit Host Standby mode #
# Rebalance cluster with DRS #
# #
# #Script finished #
# Next host...> #
# #
#====================================================================#
# NOTE: #
# #
# - Run this script first in a test environment #
# - Make sure youre ESXi host - vSwitch0 have multiple pNIC's #
# and can access both networks/gateway's #
# - Don't forgot to update vCenter Cluster das.isolationaddress2 #
# if vCenter is configured in a new subnet #
# - Don't forgot to update DNS (A) records at your DNS servers #
# with with new ESXi host Management ip-addresses #
# - Check if the correct pNIC's are configured for NIC Teaming #
# - Check if the correct VMkernel is selected for gateway config #
# - This script is written with VMware vSphere PowerCLI 5.0.0 #
# #
#====================================================================#
# CUSTOM DEFINITIONS #
#====================================================================#
$vCenterServer = "vCENTER SERVER NAME BY DNS"
$vCenterUsername = "vCENTER DOMAIN\USERNAME"
$vCenterPassword = "vCENTER PASSWORD"
$vCenterDatacenter = "vCENTER DATACENTER NAME"
$vCenterCluster = "vCENTER CLUSTERNAME"
$ESXiHost = "ESXi HOSTS BY DNS"
$RootUser = "ROOT USER ACCOUNT TO CONFIGURE/CONNECT HOST"
$RootPassword = "ROOT PASSWORD TO CONFIGURE/CONNECT HOST"
$Old_MGMT_Network = "ORIGINAL MANAGEMENT VMKERNEL NAME"
$New_MGMT_Network = "NEW MANAGEMENT VMKERNEL IPADDRESS"
$New_MGMT_Subnet = "NEW MANAGEMENT VMKERNEL SUBNET"
$New_VMK_Gateway = "NEW MANAGEMENT VMKERNEL GATEWAY"
$New_DNS01 = "NEW PRIMARY DNS SERVER TO CONFIGURE"
$New_DNS02 = "NEW SECUNDARY DNS SERVER TO CONFIGURE"
New-VICredentialStoreItem -Host "$vCenterServer" -User "$vCenterUsername" -Password "$vCenterPassword" | out-null
New-VICredentialStoreItem -Host "$ESXiHost" -User "$RootUser" -Password "$RootPassword" | out-null
Write-Host "Script will start..." -foregroundcolor yellow
#====================================================================#
# FASE 1 - vCENTER: MAINTENANCE AND REMOVE HOST FROM vCENTER #
#====================================================================#
Write-Host "Connect to vCenter Server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenterServer" | out-null
Sleep 10
#====================================================================#
Write-Host "Enter host in Maintenance mode" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Maintenance" -RunAsync | out-null
#====================================================================#
Write-Host "Disconnect host from vCenter Server" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Disconnected" -RunAsync | out-null
#====================================================================#
Write-Host "Tell DRS to re-balance VMs including the rejoined host" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster "$vCenterCluster" | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation | out-null
#====================================================================#
Write-Host "Remove host from vCenter Server" -foregroundcolor green
#====================================================================#
Remove-VMHost "$ESXiHost" -Confirm:$false | out-null
#====================================================================#
Write-Host "Disconnect from vCenter Server" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null
#====================================================================#
# FASE 2 - HOST: RE-CONFIGURE MANAGEMENT NETWORK #
#====================================================================#
Write-Host "Connect directly to ESXi host" -foregroundcolor green
#====================================================================#
Connect-VIServer "$ESXiHost" | out-null
Sleep 10
#====================================================================#
Write-Host "Configure new management network" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | New-VMHostNetworkAdapter -VirtualSwitch "vSwitch0" -PortGroup "MGMT Network" -IP "$New_MGMT_Network" -SubnetMask "$New_MGMT_Subnet" -ManagementTrafficEnabled:$true -Confirm:$false | out-null
#====================================================================#
Write-Host "Configure vSwitch0 - MGMT NIC Teaming Policy" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | Get-VirtualPortGroup -name "MGMT Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 | out-null
Get-VMHost "$ESXiHost" | Get-VirtualPortGroup -name "MGMT Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic2 | out-null
#====================================================================#
Write-Host "Configure new DNS servers" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress "$New_DNS01","$New_DNS02" | out-null
#====================================================================#
Write-Host "Change VMkernel Gateway" -foregroundcolor green
#====================================================================#
$net = Get-VMHostNetwork
$net | Set-VMHostNetwork -VMKernelGateway "$New_VMK_Gateway" -VMKernelGatewayDevice "vmk2" | out-null
#====================================================================#
Write-Host "Reboot ESXi Host" -foregroundcolor green
#====================================================================#
Restart-VMHost -VMHost "$ESXiHost" -Confirm:$false | out-null
#====================================================================#
Write-Host "Disconnect from ESXi host" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Sleep 360
#====================================================================#
# FASE 3 - vCENTER: EXIT MAINTENANCE AND RE-ADD HOST TO vCENTER #
#====================================================================#
Write-Host "Connect to vCenter Server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenterServer" | out-null
Sleep 10
#====================================================================#
Write-Host "New Management Network to vCenter Server host file" -foregroundcolor green
#====================================================================#
$hostsPath = “$env:windir\System32\drivers\etc\hosts”
$hosts = get-content $hostsPath
$string = “$New_MGMT_Network $ESXiHost”
$hosts = $hosts + $string
$hosts | Out-File $hostsPath -enc ascii
#====================================================================#
Write-Host "Add ESXi host to vCenter Server" -foregroundcolor green
#====================================================================#
Add-VMHost "$ESXiHost" -location (Get-Datacenter -name "$vCenterDatacenter" | Get-Cluster -name "$vCenterCluster") -user root -password $RootPassword -force | out-null
#====================================================================#
Write-Host "Remove old Management Network from host" -foregroundcolor green
#====================================================================#
#$vNic = Get-VMHostNetworkAdapter -VMHost $ESXiHost | where {$_.PortgroupName -eq $Old_MGMT_Network} | out-null
#Remove-VMHostNetworkAdapter -Nic $vNic | out-null
#====================================================================#
Write-Host "Exit host from Maintenance mode" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Connected" -RunAsync | out-null
#====================================================================#
Write-Host "Tell DRS to re-balance VMs including the rejoined host" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster "$vCenterCluster" | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation | out-null
#====================================================================#
Write-Host "Disconnect from vCenter Server" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null
#====================================================================#
# FASE 4 - SCRIPT FINISHED #
#====================================================================#
Write-Host "Script finished, please check error log..." -foregroundcolor yellow
#====================================================================#
The script is finished:

Custom settings:
$vCenterServer = "vCENTER SERVER NAME BY DNS"
$vCenterUsername = "vCENTER DOMAIN\USERNAME"
$vCenterPassword = "vCENTER PASSWORD"
$vCenterDatacenter = "vCENTER DATACENTER NAME"
$vCenterCluster = "vCENTER CLUSTERNAME"
$ESXiHost = "ESXi HOSTS BY DNS"
$RootUser = "ROOT USER ACCOUNT TO CONFIGURE/CONNECT HOST"
$RootPassword = "ROOT PASSWORD TO CONFIGURE/CONNECT HOST"
$Old_MGMT_Network = "ORIGINAL MANAGEMENT VMKERNEL NAME"
$New_MGMT_Network = "NEW MANAGEMENT VMKERNEL IPADDRESS"
$New_MGMT_Subnet = "NEW MANAGEMENT VMKERNEL SUBNET"
$New_VMK_Gateway = "NEW MANAGEMENT VMKERNEL GATEWAY"
$New_DNS01 = "NEW PRIMARY DNS SERVER TO CONFIGURE"
$New_DNS02 = "NEW SECUNDARY DNS SERVER TO CONFIGURE"
Categories: VMware Tags: Change VMkernel gateway, Datacenter, IP Change, IP omnummering, Migrate to new datacenter, Move, PowerCLI, Script, vCenter 5.0, VMware, vSphere 5
Last week I received some warnings at some HP Proliant DL380 G7’s, the warning message:
Host Baseboard Management Controller status

The HP branded VMware vSphere 5 installation (build 474610) detected that my colleague disconnected the UTP cable at the ILO interface.. okay.. good to know
If you don’t use ILO (not recommended) you can disable the ILO interface at the ILO bios
Global iLO 3 Settings:
Lights-Out Functionality [DISABLED]
iLO 3 ROM-Based Setup Utility [DISABLED]
Require iLO 3 RBSU Login [DISABLED]
Show iLO 3 IP during POST [DISABLED]
Sometimes.. grrr, stupid me!!.. I’ve configured last week a new Windows 7 x64 virtual machine, but this machine suspend itself after 30 minutes, I thought it was a bug.. couldn’t find any setting configured in vCenter or the particular host but saw only this messages:
Virtual machine is suspended – by User

Okay… shame shame.. the solution:

Tip: Always configure profile: High performance
Last week I need to locate some traffic from physical switches to my virtual environment.. I need to find out which MAC address belong to which virtual machine (+ adapter).. time to script this include menu
#====================================================================#
# SCRIPT: Find_VM_by_MAC_address_menu.ps1 #
# FUNCTION: Find VM (+ adapter) by MAC address with easy menu #
# OWNER: Sander Daems #
# CREATED: 11/01/2011 #
# MODIFIED: 11/01/2011 #
# VERSION: v.1.0 #
#====================================================================#
# CHANGELOG: #
# #
# v.1.0 #
# - Created script; #
# #
#====================================================================#
# HOST - CUSTOM DEFINITIONS #
#====================================================================#
Write-Host "Let's find that damn address" -foregroundcolor green
#====================================================================#
$cluster = read-host "Select Cluster name"
$macaddress = read-host "Select MAC Address to find"
#====================================================================#
# Script #
#====================================================================#
Get-Cluster $cluster | Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -eq "$macaddress"} | Format-List -Property *
#====================================================================#

To prepare a SAN to SAN migration I need to list all virtual machines with RAW Device Mappings, I found a very nice script at Pastebin (I’ve this you’re script, please comment to receive the credits), the script:
$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or
($dev.Backing.CompatibilityMode -eq "virtualMode")){
$row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName
$row.VMName = $vm.Name
$esx = Get-View $vm.Runtime.Host
$row.VMHost = ($esx).Name
$row.HDDeviceName = $dev.Backing.DeviceName
$row.HDFileName = $dev.Backing.FileName
$row.HDMode = $dev.Backing.CompatibilityMode
$row.HDSize = $dev.CapacityInKB
$row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName
$report += $row
}
}
}
}
$report

Ps. the script can take a while to list…
Upgrade VMware Tools, all virtual machines in cluster:
Get-Cluster "Productie" | Get-VM | Update-Tools –NoReboot
Upgrade VMware Tools, located in folder:
Get-Cluster "Productie" | Get-Folder "Beheer servers" | Get-VM | Update-Tools –NoReboot
Upgrade VMware Tools, selected virtual machine:
Get-Cluster "Productie" | Get-VM "BHR-SVR11" | Update-Tools –NoReboot
Get VMware-Tools versions:
Get-View -ViewType VirtualMachine | select Name, @{ Name=”ToolsVersion”;
Expression={$_.config.tools.toolsVersion}}

More information: VMware , VMware
Do you have a dream to go to VMworld 2011 in Las Vegas? Here’s your chance to attend the most expected event of this summer! You will be entered into a drawing to win a FREE pass to VMworld 2011 in Las Vegas. Onsite registration for VMworld is $2195, but if you’re a winner you’ll be attending VMworld for FREE with thousands of other IT innovators as you learn how to unlock the full power of virtualization and cloud computing for your organization.
The Rules:
- The full Conference Pass will be randomly drawn from StarWind end-user entries
- You must be able to attend VMworld 2011 in Las Vegas, Nevada
- Only one valid entry per person
- Contest entry must be received by Friday August 5th, 7pm EST. No entries will be considered after 7pm EST
- The winner will be randomly drawn by StarWind on Monday, August 8th
How To Enter:
- Send us your Success Story about StarWind solution on marketing@starwindsoftware.com before August 5th, 2011
The results will be announced on August 8th, 2011 on StarWindSoftware.com, and the winner will be notified via email.
