Tag Archives: datastores

Find LUN ID’s in VMware with Powershell

Determining the LUN ID for a specific LUN in your VMware Infrastructure used to be simple. It was listed as one of the properties of the datastore you selected in the VI Client. Nowadays, more often than not, I dont see the LUN ID in the vSphere Client. Instead, I see some sort of identifier like “EMC Fibre Channel Disk (sym.12673548127)”.
Even more unfortunate is the fact that all my scripts show the same identifier, where they used to show the LUN ID. So I decided to create a script that can translate the identifier (sometimes referred to as Canonical Name) back to a LUN ID.
By the way: in the vSphere Client, you can still find the LUN ID by opening the datastore’s properties window and clicking Manage Paths. Or you could write down the canonical name, switch to the devices view and look up the device there. That is essentially what my script does for you.
Here we go:
Continue reading


Check VMware Configuration with Powershell

I have promised you I would post this script, so here it is!

This Powershell script generates an overview of any items that are not available to every ESX server in a VMware cluster. These items might prevent your vm’s being vmotioned by DRS or restarted by HA. Pretty serious business, I’d say!

The items involved are:
1. datastores
2. LUNs (important when using Raw Device Mappings)
3. port groups

The output is a nicely formatted HTML page showing not only which items are misconfigured, but also where the are available and where they are absent.

Here’s an example:
Compare Screenshot

And here’s the script:
Compare-Clusters (Rename to .ps1)


Compare Cluster Datastores with Powershell

I showed you before how to compare the datastores for two ESX Servers using the VI Toolkit. But ideally, one would like to compare all ESX servers in a cluster to ensure VMotion and HA compatibility.
So I started scripting and it turns out to be pretty simple: only 4 lines of code in Powershell! It does the comparison for all your clusters and returns clean little tables with datastores you should investigate.


ForEach ($Cluster in (Get-Cluster | Sort Name))
$VMHosts = Get-Cluster $Cluster.Name | Get-VMHost
$Datastores = $VMHosts | Get-Datastore
$VMHosts | ForEach {Compare-Object $Datastores ($_ | Get-Datastore)} | ForEach {$_.InputObject} | Sort Name | Select @{N=$Cluster.Name;E={$_.Name}} -Unique | Format-Table




Coming very soon: a full-blown script that compares datastores, LUNs and portgroups across your clusters ánd identifies exactly where the differences are! Stay tuned…

Another way to gather VMware disk info with Powershell

I’ve created another way to gather and display VMware Virtual Disk information with the Powershell VI Toolkit.

The attached script generates a csv-file with all Virtual Machines’ Disks, in which Datastore they are stored, the LUN IDs of the extents that make up this Datastore (in HEX) and the Vendor of the SAN those LUNs are on (just in case you have multiple). Simpy a great way to determine which LUNs are used by which virtual server(s) in a complex environment.


By the way: the script is filled with comments to allow you to learn how it works.

create-vmdiskoverview (Rename to .ps1)



Compare ESX configurations with Powershell

One of the challenges in managing a large VMware Infrastructure is keeping all ESX Servers within a cluster equal. This is essential for having vmotion capabilities and therefore essential for a solid HA configuration. I have showed you earlier how to add the LUN Count for each ESX Server to your VI Client. This allows you to spot differences quickly. But finding exactly which datastores are missing on which ESX Server can be a bigger challenge.

Here are some small functions that can help you determine where the major differences are.

Comparing datastores:

function Compare-VMHostDatastores
$a = Get-VMHost $host1 | Get-Datastore | %{$_.Name}
$b = Get-VMHost $host2 | Get-Datastore | %{$_.Name}
Compare-Object $a $b

Compare-VMHostDatastores esxServer1 esxServer2

InputObject                         SideIndicator
———–                                ————-
esxServer1_Local             <=
esxServer2_Local             =>
DATASTORE_TEST1         =>

And comparing Port Groups:

function Compare-VMHostPortgroups
$a = Get-VirtualPortGroup (Get-VMHost $host1) | %{$_.Name}
$b = Get-VirtualPortGroup (Get-VMHost $host2) | %{$_.Name}
Compare-Object $a $b

Compare-VMHostPortgroups esxServer1 esxServer2

InputObject                SideIndicator
———–                      ————-
PortGroup_TEST     <=
Internal                       <=

Maybe you prefer to go the other way around and check to which ESX servers a specific datastore is attached?

function Get-DatastoreHosts
Get-VMHost -Datastore (Get-Datastore $datastore) | Sort Name | %{$_.Name}

PS D:Scripts> Get-DatastoreHosts DATASTORE_TEST1


Thank Microsoft for Powershell and the Compare-Object cmdlet!


Get VMware Disk Usage with Powershell

Using VMware seriously requires a lot of (shared) storage. This kind of storage (on a SAN for instance) is quite expensive. So you might want to check if you are wasting a lot of this space. When you look at the storage in VMware, it consists of multiple abstraction layers. A virtual machine has one or more Logical Disks, which are indicated by driveletters. You can use WMI to determine the amount of used and free space (Win32_LogicalDisk). One or more logical disks are contained in a partition. One or more partitions reside on a physical disk. That physical disk is really a virtual disk, a vmdk file to be precise. One or more vmdk files reside in a Datastore, which can be found on a LUN on your SAN.
The following script enumerates most of these layers (from logical disk to datastore) and calculates the used and free space. The final line exports the results to a csv file for use in Excel. And the script also helps you to calculate the average free space by showing the totals without the duplicates (don’t try to average the averages in excel, that’s not accurate because datastores contain duplicates and averages should be weighed).

UPDATE: I have modified the script, so no more matching of disks is done based on disk size. The match is made based on SCSI IDs and WMI relations. Thanks to adavidm on the VI Toolkit Community Continue reading

Helpful scripts of the day: HTML Overview of VMs and Datastores

Today’s helpful scripts are ready to use scripts that generate an overview of your VM’s and your Datastores and save it to a HTML file. Great for reporting purposes. Easy to modify to meet your needs. Give them a try:

Get-DatastoreSizes (Rename to .ps1)

This one shows datastores with Used Space in GB, Free Space in GB and % Free Space.

Export-VMs (Rename to .ps1)

This one shows vm’s with OS Name, Total Disk Size in GB and Memory Size in GB.



Powershell Oneliner #6

Today’s oneliner is an incredibly fast way to check the usage of your VMware datastores. You should first connect to Virtual Center in the following way:

$VC = Connect-VIServer “YourVCServerName”

Here comes the oneliner:

Get-Datastore | Sort-Object Name | %{Get-View $_.Id} | Format-Table @{Label=”Name”;Expression={$_.info.name}}, @{Label=”NumVMs”;Expression={$_.vm.length}}

Only interested in datastores that are not used? Use the Where-Object cmdlet:

Get-Datastore | Sort-Object Name | %{Get-View $_.Id} | Where {$_.vm.length -eq 0} | Format-Table @{Label=”Name”;Expression={$_.info.name}}, @{Label=”NumVMs”;Expression={$_.vm.length}}

But watch out! Consider a vm with a disk in datastore A and the vmx in datastore B. When you create a snapshot of the vm, the delta files of all disks will be stored with the vmx (in datastore B). The script (as does the VI Client) will show the vm to be not connected to datastore A!


Where’s that vmdk at?

Do your vm’s have multiple virtual disks? Do you use different datastores for your vmdk’s? Are you ever wondering where the disk files of each of your vm’s is stored? Yes? Well, I’ve got something to help you out.

Today’s handy script of the day creates an overview of the locations of all your vmdk files in the form of a csv file.

Of course you Powershell guru’s can work some simple magic to output it to a HTML page, a Word document of straight to the printer. (If you don’t, but would like to, drop me a comment and I’ll try to respond asap).

The script is attached for easy use. Just fill in your Virtual Center server name, rename the file to .ps1 and enjoy!