Wednesday, November 19, 2014

Report VMFS Datastores and their Member Hosts

This is my second post and I was recently requested by one of my colleagues to help him with a report which shows Datastores, Capacity, Freespace along with the cluster name and hosts that it is connected to. This can connect to multiple vCenters and push separate reports for each of the vCenter.

$vcservers = "", ""
foreach($vcserver in $vcservers){
Connect-VIServer $vcserver -Port 443
$report = @()
$DS = Get-Datastore | Where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess} | Sort Name
foreach ($store in $DS){
  $memberhosts = ($store | Get-VMHost | Select -ExpandProperty Name) -join ","
  $cluster = ($store | Get-VMHost | Sort Name | Select -First 1 | Get-Cluster).Name
  $list = "" | Select-Object Name, CapacityGB, FreeGB, PercFree, FileSystem, ClusterName, MemberHosts
  $list.Name = $store.Name
 $list.CapacityGB = "{0:N2}" -f ($store.capacityMB/1kb)
 $list.FreeGB = "{0:n2}" -f ($store.FreeSpaceMB/1kb)
 $list.PercFree = "{0:N2}" -f (100 * $store.FreeSpaceMB/$store.CapacityMB)
 $list.FileSystem = $store.Type
 $list.ClusterName = $cluster
 $list.MemberHosts = $memberhosts
 $report += $list
$report | Export-Csv "C:\Temp\Output\$vcserver.csv" -NoTypeInformation
Disconnect-VIServer $vcserver -Confirm:$false
Clear-Variable report

Sample output below --

There could be much easier ways to do this, but this one just worked out for me.

Wednesday, October 22, 2014

PowerCLI - Add PortGroups to Standard vSwitch.

If your environment uses Standard vSwitches it is more likely that you often end up adding a portgroup on all the hosts in a cluster. This becomes even more tedious task when you have multiple portgroups to add.

This script helps you to add new portgroups to an existing vSwitch. You can also connect to an ESXi Host directly if you have a standalone host (which is rare in Prod environments though)..

$vcserver = "vCenterFQDN/IP"
$portvc = "443"
$myvSwitch ="Your vSwitch (EX: vSwitch1)"
Connect-VIServer $vcserver -Port $portvc -Credential (Get-Credential)
$hosts = Get-VMHost -Location "Cluster_Name" | Sort Name
foreach($host in $hosts){

# Enable below line if you want to create a new vSwitch named with $myvSwitch and assign NICs 1,3,4,5 to the vSwitch.
#$host | New-VirtualSwitch -Name $myvSwitch -Nic vmnic1, vmnic3, vmnic4, vmnic5

#Add new portgroups to the vSwitch named "$myvSwitch". Each portgroup/VLAN needs one line similar to the below..
$host | Get-VirtualSwitch -Name $myvSwitch | New-VirtualPortGroup "corp 80" -VLanId 80 -Confirm:$false
$host | Get-VirtualSwitch -Name $myvSwitch | New-VirtualPortGroup "corp 90" -VLanId 90 -Confirm:$false
$host | Get-VirtualSwitch -Name $myvSwitch | New-VirtualPortGroup "corp 100" -VLanId 100 -Confirm:$false
Disconnect-VIServer $vcserver -confirm:$false

***PS: Test it before you run in a Prod Cluster. ***

Friday, August 29, 2014

Kick Start!!

All these years I was thinking to start a blog on the technology that I work on. Better late than never. Now is the time for me to kick start this effort.

I am Pardha Nallan working as a Vmware Architect with a US based Records Management Company. I'm in the industry for little more than 9 years and working in Vmware Virtualization for the past 5 years. I work on VMware vSphere Stack, vSphere PowerCLI, vCenter Orchestrator, vCloud Director, vCloud Automation Center etc..

I have a few IT Certifications like VCP 4&5, ITIL v3 Foundation, MCTS etc.. and aiming towards VCAP Certifications as well.

I can be reached at and my twitter handle is @pardhanallan. My linkedin profile is

Let me start sharing what I know and learn what others know.

Pardha Nallan