Collect Service Tags/Serial Numbers using PowerCLI

Here is a useful PowerCLI script to collect Service Tags and Serial Numbers of the servers/blades. If you are maintaining an Inventory or gathering some information about the current hardware in your Datacenter this might be very useful to gather these information.

Run this script in your vCenter server and you will get the similar output as below. I have highlighted the serial numbers of the blades and servers in RED. In UCS you have the Chassis serial number and the blade serial number (right side) in the output.
Create a script after copying the below code and save as a .ps1 file. Execute the script and you get the service tags of your servers. You may need to add your vCenter server IP or FQDN, username and password to this script. Also if you wish to export this to a .csv file add the Exprt-csv pipeline to export to a csv file.

Download the script.

A piece of code to Power Down the list of ESXi hosts

We had a quick requirement to power down the entire VMware ESXi environment and we powering down one by one was time consuming work so created this piece of code to bring all them down at once.

All we had to do is placing a text file named “VM_list.txt” in a folder, updating the FQDNs of all the host and executing the PowerShell script in the folder.

Just for sharing purpose I’m just adding this to the blog…

VMware Power CLI 6.5.2 Released

Three months ago VMware released VMware PowerCLI 6.5.1 with new features and you don’t need to use the old PowerCLI application to use this release. With WMware PowerCLI 6.5.1 release you can install the modules to your PowerShell though the Windows PowerShell Gallery. You can read my previous post from here.

With this release there are few improvements introduced.
  • Addition of the ‘InventoryLocation’ parameter to the following cmdlets: Move-VM, Import-VApp, New-VApp
  • Ability to mount a Content Library sourced ISO with the New-CDDrive cmdlet
  • Updated Support Around Experimental Features

If you have already installed the VMware PowerCLI 6.5.1 you can simply update the modules to the 6.5.2 following the below steps.

Type “Update-Module VMware.PowerCLI“, type “y” and hit enter to update the modules


It will start the module upgrade

Once it completed the upgrade check the added module using “Get-Module VMware.* -ListAvailable

That’s it!

More about VMware PowerCLI 6.5.2 :

Convert Network Adapter to VMXNET 3 from E1000

Have you ever wanted to re-configure your Virtual Machine with the up to date Virtual hardware configurations? then you should be looking for something like this. I wanted to update the Virtual network adapter to VMXNET 3 for my Virtual Machines and I could do that easily using the VMware PowerCLI.

This piece of PowerCLI command converts the Network Adapter without changing the MAC address of the adapter. If you have MAC address bind license application you don’t need to manually change the MAC Address after changing adapter.

For Linux Virtual Machines….

No manual IP configuration required and VMware tools should be installed which is the Primary requirement for the VMXNET3 adapter

For Windows Virtual Machines….

Manual IP configuration required and ghost adapter should be removed manually if required. Tools is a primary requirement for this adapter.

VMware PowerCLI 6.5.1 – New Release Installation

Some of may already know that VMware has released the PowerShell 6.5.1 and there are lot’s of changes and improvements in the Modules, cmdlets and installation process. You may installed the PowerCLI as a separate component in your local management computer and used the PowerCLI cmd console to execute the commands. With this release you don’t need to worry about the separate installation for this as it comes as a PowerShell module in the PowerShell Gallery. 
Here are the steps of online installation of the PowerCLI from the PowerShell Gallery. 
I was trying to install this on one of our management server which was setup with Windows Server 2008 R2 SP1. It was a fresh installation and “Find-Module” command was not recognized as a PowerShell command. So I downloaded the “Windows Management Framework 5.0” from the Microsoft website and installed the update for the Windows 2008 manually. 
After that, I opened a PowerShell with “Run as Administrator” and followed the below steps. 
Typed the “Find-Module -Name VMware.PowerCLI” PowerShell command and it installed the NuGet Provider to download the PowerCLI modules and typed “Y” to continue the NuGet installation
Typed “Install-Module -Name VMware.PowerCLI” to install the required modules, it gave me a warning saying this is an “Untrusted Repository” typed “Y” to accept the warning.
It started the installation after that
Once it completed the installation typed “Get-Module VMware* -ListAvailable” command to view the available modules
I tried to connect to the vCenter and it was successfully connected
These steps are only for the online installation, if you have a Management computer which doesn’t have an internet connectivity you need to save them as a offline copy and need to copy to the modules folder in the Management computer. 
For that followed the below steps :

Used “Save-Module -Name VMware.PowerCLI -Path C:<destination_folder> to save the modules as offline copies.

It was exported the libraries to the given folder

Checked and confirmed the libraries by typing “Get-ChildItem -Path <destination_path_of_the_libraries”>

Checked the folder path manually and folders were there

Copied these folders to the location which you can see after executing the “$ENV.PSModulePath” command

Create a Desktop Shortcut for the PowerCLI console

Most of VMware users want to keep the PowerCLI launch shortcut in their desktops. It was the practice for the later versions of the PowerCLI. Here you have to create a Shortcut manually in your desktop.

In the start menu search the PowerCLI and Create a generic x64 shortcut in your desktop

Name it as “PowerCLI 6.5.1”

Right-Clicked on the Shortcut and selected the properties of the PowerCli shortcut, added the below attributes

Target: C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -noe -c “Import-Module VMware.PowerCLI”
Start In: C:
Shortcut Key: None
Run: Normal Window
Comment: VMware PowerCLI 6.5.1

So now you will be able to open the PowerCli 6.5.1 straight away from the PowerShell.

This is the Official video from VMware  :