PoshCode Archive  Artifact Content

Artifact 44594cf703316b708ea2fc623713fb9c8a06535eaff8a6f301e42b2ab75d4369:

  • File VMWare-DS-Migration.ps1 — part of check-in [22a0afdd0e] at 2018-06-10 13:33:20 on branch trunk — If you need to migrate a VM to a different Datastore but do not have the vMotion license (cant migrate while the VM is powered on), this script can be scheduled to run out of hours and will move the VM’s Datastore and set the disk to thin prov (user: AdrianWoodrup size: 1501)

# encoding: ascii
# api: powershell
# title: VMWare DS Migration
# description: If you need to migrate a VM to a different Datastore but do not have the vMotion license (cant migrate while the VM is powered on), this script can be scheduled to run out of hours and will move the VM’s Datastore and set the disk to thin prov
# version: 0.1
# author: AdrianWoodrup
# license: CC0
# x-poshcode-id: 3938
# x-archived: 2013-02-16T03:19:57
# x-published: 2013-02-12T13:54:00
#
#
#####################################################
# Migrate a VM to new storage and set to Thin Prov  #
#####################################################
# Set the VM name you want to move
$Server = 'SERVERNAME'
# Set the location you want to move the VM to
$DataStore = 'DATASTORE'
# Set the vCenter name (should not need to be changed)
$VCName = 'VCENTERSERVER'
# Load VMWare Snapin
asnp VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Connect to vCenter
Connect-VIServer $VCName -User 'USERNAME' -Password 'PASSWORD'
# Check if server is powered off, if not perform a clean shutdown
$VMPower = Get-VM $Server
If($VMPower.PowerState -eq 'PoweredOn'){
	Get-VM $Server | Shutdown-VMGuest
	}
# Wait for VM to stop
Start-Sleep -s 30
# Move the server to the new storage and set it to thin provisioned 
Move-VM $Server -Datastore $DataStore -DiskStorageFormat Thin
# Power on the VM
#Start-VM $Server 
# disconnect from the vCenter CLI 
Disconnect-VIServer -Confirm:$False