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

We take the help of perl script as mentioned below save below script to file

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

use strict;
use warnings;

use VMware::VIRuntime;


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

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


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
 echo "===================$LINE========================" >> /vmware/Windows-Inventory-List.log 
 perl /vmware/ --server ${LINE} --username root --password inScott! >> /vmware/Windows-Inventory-List.log 2>&1
 echo -e "\n\n" >> /vmware/Windows-Inventory-List.log

Run above shell script 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