In the process of moving from an old vCenter to a new vCenter (same storage) you might need consider some things
- What do you want to do and when?
- Commit snapshots? (consolidate disks)
- Remove floppys?
- Remove from old vCenter
- Add to new vCenter
- Add hardware?
- Add hotplug cpu/mem?
- Snapshot before upgrade virtual hardware?
- Hardware upgrade?
- New network name?
- Upgrade vmware tools (reboot?) ?
Scripts to help with this, both on the way down and up so it will be made exactly the same every time and dont do anything else than what is set out to do. Im not used to powershell so bare with me.
What if we have vm appliances with very old hardware versions? should those get upgraded directly or does it need more digging to see if its supported? In this version its not yet considered and if we have a CSV file with alot of vm’s we can migrate/move all these vms at once but in doing so you have little control over whats happening in your vCenter environment, letting this beast loose on 100+ vms might be bad for you hart.
<#
.Synopsis
Move to new VC, deregister
.DESCRIPTION
Remove ISO files to CD
Shutdown a vm
Remove floppy
Consolidate disks
Deregister VM
.EXAMPLE
Enable-VMHotAdd -VM MyVM -Device CPU
.EXAMPLE
$vm = "MyVM"
$vm | vcold.ps1
.EXAMPLE
$vmlist = "MyVM1","MyVM2","MyVM3"
$vmlist | % { Enable-VMHotAdd -VM $_ -Device CPU }
.REMARKS
VM's need to register in the new VC with vcnew script
#>
# See to that only 1 input is made
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string] $vm = $null
)
# Functions
function disconect_vm_cdrom ()
{
Get-VM $vm | Get-CDDrive | Where {$_.ConnectionState.Connected} | Set-CDDrive -Connected $false -Confirm:$false
}
# Power off VM
Write-Host -foregroundcolor yellow "Shutdown-VMGuest -VM $vm -Confirm:$false"
Shutdown-VMGuest -VM $vm -Confirm:$false
#Wait for Shutdown to complete
do {
#Wait 5 seconds
Write-Host -foregroundcolor yellow "waiting 5 seconds to check powerstate"
Start-Sleep -s 5
#Check the power status
$MyVM = Get-VM -Name $vm
$status = $MyVM.PowerState
}until($status -eq "PoweredOff")
Write-Host -foregroundcolor yellow "powerstate is PoweredOff"
# remove floppy
Write-Host -foregroundcolor yellow "get-vm $vm | Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false"
get-vm $vm | Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false
Write-Host -foregroundcolor yellow "disconect_vm_cdrom $vm"
disconect_vm_cdrom $vm
# Consolidate disks ?
Write-Host -foregroundcolor yellow "ConsolidateVMDisks"
(Get-VM -Name "$vm").ExtensionData.ConsolidateVMDisks()
# before deregister, show VMX filepath and NetworkName
Write-Host -foregroundcolor yellow "Get VMX Filepath for $vm"
Get-VM -Name $vm | Get-View | %{$_.Config.Files.VmPathName}
Write-Host -foregroundcolor yellow "Show network name"
Get-VirtualPortGroup -VM $vm|select Name
# Deregister VM from VC OLD
Write-Host -foregroundcolor yellow "Removing from inventory: Remove-Inventory -Item $vm -Confirm:$false"
Remove-Inventory -Item $vm -Confirm:$false
Register and do some stuff into the new vCenter
<#
.Synopsis
Register VM's from VCOLD.PS1
.DESCRIPTION
Register VM from DS
Snapshot (in case of restore)
HW Upgrade v10 if old hw version is 8 or newer
power on
vmware tools upgrade
reboot
.EXAMPLE
Enable-VMHotAdd -VM MyVM -Device CPU
.EXAMPLE
$vm = "MyVM"
$vm | vcold.ps1
.EXAMPLE
$vmlist = "MyVM1","MyVM2","MyVM3"
$vmlist | % { Enable-VMHotAdd -VM $_ -Device CPU }
.REMARKS
VM's need to register in the new VC with vcnew script
#>
# Se to that correctinput is made
param (
[string]$ESXHost = $( Read-Host "Input ESXHost, please" ),
[string]$VMXFile = $( Read-Host "Input VMXFile, please" ),
[string]$Network = $( Read-Host "Input Network, please" ),
[switch]$force = $false
)
# register VM with DISKPATH
Write-Host -foregroundcolor yellow "New-VM -VMFilePath $VMXFile -VMHost $ESXHost -NetworkName $Network"
New-VM -VMFilePath $VMXFile -VMHost $ESXHost -NetworkName $Network
# Take a snapshot on the VM
New-Snapshot -Name "Beforev10" -VM $vm -Confirm:$false
# Hardwareversion upgrade
Write-Host -foregroundcolor yellow "set-vm -Version v10 $vm -Confirm:$false"
set-vm -Version v10 $vm -Confirm:$false
# Power On and wait a while
Write-Host -foregroundcolor yellow "Start-VM -VM $vm -Confirm:$false"
Start-VM -VM $vm -Confirm:$false
#Wait for Shutdown to complete
do {
#Wait 5 seconds
echo "waiting 40 seconds to check powerstate"
Start-Sleep -s 40
#Check the power status
$MyVM = Get-VM -Name $vm
$status = $MyVM.PowerState
}until($status -eq "PoweredOn")
echo "powerstate is PoweredOn"
# Upgrade vmware tools
Write-Host -foregroundcolor yellow "Mount-Tools -VM $vm"
Mount-Tools -VM $vm
Write-Host -foregroundcolor yellow "Update-Tools -VM $vm -NoReboot"
Update-Tools -VM $vm -NoReboot
Write-Host -foregroundcolor yellow "Dismount-Tools -VM $vm"
Dismount-Tools -VM $vm
Du måste vara inloggad för att kunna skicka en kommentar.