VMware vSphere – How to script vMotion for your VMs

vMotion Script

VMware vMotion is a pretty good feature regarding the availability and load balancing in your vSphere environment. Today i created a vMotion script to help me create a backup with a backup software.

As so many times my blog posts are the result of a problem i had and for which i needed a solution. It shouldn’t be different today. I worked in my vSphere homelab. I created some virtual machines and installed my backup software of choice. My idea was to have a backup before doing any work with the VMs, just in case i screw it up. So i can easily go back to a known good state of the VM and try again. But this task wasn’t so easy.

As a vExpert, VMCE, MVP, Trainer or many other different tech people you can request a NFR license key for Veeam Availability Suite. So did i. The NFR key was delivered quickly to my mailbox, and was even faster installed in Veeam. But there was a catch. At least my NFR license is limited to two sockets, but with no limits for protected VMs, and it comes with a full 1-year retention period, instead of just 30 days as the regular trial.

So i had to deal with the fact that only one host (i’ve got three hosts in my lab with two sockets each) is protected by Veeam. This limitation woke the hunter in me because i had to find a solution. My goal was to backup all my VMs but with only two licensed sockets. The approach I chose was to set vSphere DRS to manual, then do a vMotion of all VMs to the host which helds the Veeam license, doing a backup and set DRS back to fully automated after backup. If you are working with ressource pools you shouldn’t disable DRS, because that results in removing the ressource pools. But there is a workaround for that too. Instead of creating a new problem i did the easy way and just set DRS to manual.

How to get the vMotion script

If you’re familiar with GitHub you can download my script from there:


For any other user i’ll provide the script directly here:

[code lang=”powershell” gutter=”true”]
# This script will start a vMotion of all virtual machines on a specified datastore to a specified ESXi host.
# If you are working with a backup software which is licensed to a specific host, # this will probably help you.
# Only recommended in smaller environments or if you have enough ressources on this host.

# The script loads a PSSnapin; it sets some PowerCLI options; it connects to your vCenter Server with the given credentials;
# it gets all your VMs in an array; it starts then a Host vMotion of all the VMs in the array to a specified ESXi host.

# File Name : pre-backup.ps1
# Version: : 1.0
# Author : Karl Widmer (info@)
# Prerequisite : PowerShell V2 over Vista and upper / VMware PowerCLI 6
# Tested on: : Windows Server 2012 R2
# with PowerCLI : PowerCLI 6.3 Release 1 build 3737840
# with PowerShell: 4.0
# Copyright 2016 – Karl Widmer / driftar’s Blog (www.)

# Script posted over: https://www.driftar.ch

# Load PowerCLI cmdlets
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction "SilentlyContinue"

# Set PowerCLI behaviour regarding invalid certificates and deprecation warnings
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -DisplayDeprecationWarnings:$false -confirm:$false

# Define vCenter User and target Datastore
$vcHost = ‘vcenter.domain.com’
$vcUser = ‘administrator@domain.com’
$vcPass = ‘password’
$datastore = ‘your_datastore’
$cluster = ‘your_cluster’
$targetHost = Get-VMHost -Name yourhost.domain.com

# Connect to vCenter
Connect-VIServer $vcHost -User $vcUser -Password $vcPass

# Get VMs (pass array of VMs to $VMs, for example ‘get-datastore test | get-vm’)
$VMs = Get-Datastore $datastore | get-vm

# Get Cluster information to set DRS to Manual for backup window
Set-Cluster $cluster -DrsAutomationLevel Manual -Confirm:$false

Foreach($vm in $vms) {
Write-Host ("Start Host vMotion for VM ‘" + $VM.Name + "’")

Move-VM -VM (Get-VM -Name $vm) -Destination (Get-Vmhost $targethost) -RunAsync

Write-Host ("Waiting…")

Write-Host ("Host vMotion for VM ‘" + $VM.Name + "’ finished")

# This last script step should probably be executed in a post-backup script step.
# It sets the DRS automation level back to fully automated. Your VMs will then probably load-balance on your hosts.

# Set DRS on cluster back to FullyAutomated after backup window
Set-Cluster $cluster -DrsAutomationLevel FullyAutomated -Confirm:$false

Update 07.11.2016

After updating my ESXi hosts to 6.0.0 Build 4510822 my script stopped working. So i simplified the script and released version 2.0.

VMware Workstation – Save login information for remote host

This post is gona be a short one. It was once again a problem for which I needed a solution. Today i was working in my vSphere homelab. I’ve set up some more virtual machines, installed my availability software of choice and did some reading. If you are a VMware Workstation user, then you probably know the feature to connect to a remote server, like, for example a vCenter Server. That’s a pretty handy feature which i really like. You can connect to your lab environment and you can access all your VMs directly and easy, without any remote desktop and stuff.

One thing about this feature was quite annoying for me. Everytime when i connected to my lab environment i had to enter my credentials. It didn’t bother me very much, it was just annoying. So i searched for more information but there wasn’t much. Then I found a VMware communities post which asked how to clear these credentials. I did some reverse thinking and found the options in the settings of VMware Workstation.

How to save login information

If you now would like to know how you can save your credentials, then just follow this quick steps:

  1. Click on “Edit” => “Preferences…”.

  2. On “Workspace” look for “Privacy” and click the checkbox “Offer to save login information for remote hosts”.

    VMware Workstation Preferences - Workspace

  3. Aaaand you’re done.

The next time you click on your lab environment (or any other remote host) then there is a pop up which asks you if you want to save the login or not.


VMware vSphere – How to find floppy images (paravirtual SCSI)


Today’s blog post is about some tricks and treat. It’s soon Halloween, folks… Today i’m working in my vSphere homelab. I tried to create a virtual machine. Well, that wasn’t that complicated. More complex was to find the floppy images for providing the PVSCSI driver. You’ll need this driver when you’re creating a paravirtual SCSI storage controller within your virtual machine. A quick search provided a good VMware knowledgebase article which helped me. Gathering the floppy images was then easy as pie.

You can’t access the “vmimages” folders through storage browser, it shows to be empty. This is an expected behaviour because the vmimages search through vCenter Server is turned off in ESXi 4.0/4.1. And i just assume that it’s also turned off in newer ESXi versions, like 6.0 which i’m using in my homelab. Because i actually can’t find the “vmimages” folder. For my case i installed all my nested ESXi hosts from scratch, manually, so there shouldn’t be any issue. This should also happen in production environments.

But now lets start to gather this folder. How do you get your hands on it? Let me show you.

Start putty and connect to one of your ESXi hosts (SSH service has to be enabled in the security profile / firewall on your ESXi host).

Run these two commands to create a folder on a datastore where you whish to store the images:

[sourcecode language=”plain” gutter=”true”]mkdir /vmfs/volumes/<datastore_name>/floppies
mkdir /vmfs/volumes/<datastore_name>/vmtools[/sourcecode]

Where <datastore_name> is the name of a shared datastore.

Run these commands to copy the contents of the original source folder to the newly created folder on the shared datastore:

[sourcecode language=”plain” gutter=”true”]cp /productLocker/floppies/*.flp /vmfs/volumes/<datastore_name>/floppies/
cp /productLocker/vmtools/*.iso /vmfs/volumes/<datastore_name>/vmtools/[/sourcecode]

Now you’re able to mount the floppy images in your VM to get access to the paravirtual SCSI driver.

Happy virtual machine creation, and Happy Halloween too 😉


VMware VMworld EMEA 2016 – Day 4 – Closing Sessions


Yesterday was the last day of VMworld 2016 in Barcelona. It was a great day for me personally because of all those nice chats with people which i look up upon. I learned much this week, learned much about technology, future trends and i met some really nice and kind people. It’s somehow sad that it’s just one week of VMworld. But with all the early wake up at morning, walking throughout the day and probably the one or another party the evening it’s also little exhausting. Let me provide you a short overview what was on my schedule yesterday.

VMware Hands-on Labs

I took another hours to get some experience with the VMware Hands-on Labs (VMware HOL). This is a great opportunity to learn something about a product which you don’t know much about, but it’s also great to know more about an already known product. I took the labs for VSAN and VMware Horizon View. In my homelab i’m already used to work with VSAN, but i didn’t know much about Horizon View. We use it in our company to enable our technicians an easy way to connect from on the go or at home to some virtual desktops, looking at customers network documentation or doing all the reporting stuff. Now i’ve got some little more insights about that great product.

Meet the experts

The afternoon i’ve spent with chatting and exploring the solutions exchange, and too for gathering some schwag, you know that, Kev 😉 I had also the chance to get into a close circle of people (we were three) to have a chat with VMware’s senior technical marketing engineer Emad Younis about the new version of VCSA (vCenter Server Appliance). We took a look at the deployment of Platform Services Controller (PSC). And now we know to keep the deployment flat and simple. Another VMware specialist joined in, we had also a talk in the same session with Mike Foley, VMware’s guy for security of the core platform (vSphere). There we had a short insight about securing the Web Client with RSA tokens.

vSphere Troubleshooting made easy

The last session which i attended was “vSphere Troubleshooting made easy”. Well, what we saw at the presentation wasn’t that easy i think. Lots of CLI commands, lots of useful tools most people probably don’t are aware of. It was a technical deep dive in my opinion, but it was a good one. I’ll do a blog post about this session in a short while, because i think you should know some of that stuff. If you don’t had any issues with your vSphere environment then you’re a lucky guy, but you probably can too take some benefits from the following post.

Conclusion about VMworld week

This week was one of a kind. Exhausting, interesting, informative and sporty at the same time. I met some really kind persons and i’m looking forward to meet them at another time at another VMworld. But i’m starting too to miss the mountains in my home country. So one week is probably enough.

Special thanks go to Kev, Ather, Gareth, Chris, Chris, Chris, Amit, Fred and Andi. You are cool guys and i really enjoyed the time with you. You gave me some good insights about certification and how to not fail again 🙂

And another special thank you goes to CloudCredibilities CloudCredGeeg Noell. Thanks for your support in the labs and the nice memories i can take home 🙂

Please read the other VMworld posts to:

VMware VMworld EMEA 2016 – Day 3 – Announcement Overview


Today in the morning i will provide you a short overview over the recently made announcements here at VMworld Barcelona. VMware announced some long expected new product versions at the general sessions at VMworld. Lets look a little closer.

vSphere 6.5

vSphere 6.5 is the foundation of next-generation infrastructure for your next-generation apps. Decrease CapEx and OpEx, simplify data center operations and increase business efficiency through virtualization.

Learn more >>

vRealize Suite Cloud Management Platform

The enterprise-ready cloud management platform from VMware, vRealize Suite, delivers a complete solution for managing private, public and hybrid clouds. And there is a 25% discount to on this solution for some time, take advantage of this limited time opportunity.

See what’s new >>

Workspace ONE Essentials

It’s all about the digital workspace. Work from from anywhere from any device. The new Workspace ONE Essentials delivers a customer-simple experience, integrating single sign-on access to web and mobile apps. Starting at 4$ per user and month at a cloud subscription its fairly attractive to get started with Workspace ONE Essentials.


What’s new >>

Photon Platform: Built for Cloud Native Workloads

Photon platform is an enterprise cloud infrastructure platform. Give your developers the tools and services they need to build and run modern applications, while retaining control and security of your data center. Enjoy an intuitive and easy-to-use REST API, CIL and HTML5 user interface. Deliver on-demand access to high available Kubernetes clusters, scaling up or down with zero maintenance.

Discover more >>

Read the announcement blog post >>

Virtual SAN 6.5

Virtual SAN is the storage platform used in the hyper-converged systems. With version 6.5 VMware delivers new capabilities. Consolidate your data center silos, accelerate responsiveness and deliver extensibility to meet future cloud and cloud-native demands. Virtual SAN enables you to respond 10x faster, reduce TCO by 50% and makes you ready for scaling to tomorrow. Virtual SAN 6.5 now brings iSCSI access to non-virtualized workloads with iSCSI support. You can also connect to nodes togehter (2-Node Direct Connect) to save up to 20% per ROBO site. It supports the next-generation hardware, like large capacity drives with 512e support.

Get the details >>

Thats it folks for the moment. Stay tuned for more to come!

Please read the other VMworld posts to: