List All Windows Virtual Machines from ESX Server Using shell script

We came across one special requirement. We have number of ESX servers, there are N number of virtual machines hosted in those ESX servers. All Virtual machines are not Windows there are Linux and windows. Out of all virtual machines we would like to list out only windows machines. (: . List All Windows Virtual Machines Esx server Using shell script. 

Manually checking N number of ESX servers by login to each and every one, required a lot of time, but we can make use of shell script knowledge to achieve this requirement easily. 

Let’s see how to List all windows Virtual Machines from ESX server using shell script

Pre-requisite is to install Vmware Perl SDK in Linux and Vmware Tools

After installing everything required than make list of ESX servers.

Create Text File esx-server-list.txt

192.168.1.98
192.168.1.167
192.168.1.171
192.168.1.177
192.168.1.196
192.168.1.197
192.168.1.199
192.168.1.244
192.168.1.254
192.168.2.13
192.168.2.32
192.168.2.39

We take the help of perl script as mentioned below save below script to find-windows.pl file

#!/usr/bin/perl -w
#This script prints names of all VM's with Windows guest

use strict;
use warnings;

use VMware::VIRuntime;

Opts::parse();
Opts::validate();
Util::connect();

my $vm_views =
 Vim::find_entity_views(view_type => 'VirtualMachine',
 filter => { 'config.guestFullName' => qr/Windows/ });

foreach (@$vm_views) { 
 print $_->name . ": " . $_->config->guestFullName . "\n";
}

Util::disconnect();

shell script to fetch required details

#!/bin/bash -x
# Just an While loop which take list of ESX servers from text file and process
cat /vmware/esx-server-list.txt | while read LINE
do
 echo "===================$LINE========================" >> /vmware/Windows-Inventory-List.log 
 perl /vmware/find-windows.pl --server ${LINE} --username root --password inScott! >> /vmware/Windows-Inventory-List.log 2>&1
 echo -e "\n\n" >> /vmware/Windows-Inventory-List.log
done

Run above shell script sh find-windows-inventory.sh 

That’s it. 

Your job done all the windows Virtual machines stored in Windows-Inventory-List.log file

Few More Articles

Troubleshoot: VM Does Not Power On After Cloning or Deploying from Template

How to deploy OVF OVA template ESXi step by step guide

vSphere 5 vs vSphere 6 Difference between both versions

clone virtual machine without vCenter using ESXi

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

Your email address will not be published. Required fields are marked *