Wednesday, June 29, 2011

Find your VMware local VMFS datastore with powershell

To find your local VMFS datastore

Solution 1: name all your local vmfs LOCAL_xxx
Get all your local datastore by using
Get-Datastore | Get-View | Where-Object { $_.Name -match "LOCAL_*" } | Select-Object  @{n="Name";e={$_.Name}}}

Name
----
LOCAL_ESX01
LOCAL_ESX02
LOCAL_ESX03



Solution 2: use MultipleHostAccess info from Get-Datastore
(Thanks to http://blogs.vmware.com/vipowershell/2009/08/how-to-list-datastores-that-are-on-shared-storage.html?cid=6a00d8341c328153ef0120a52e7f0b970b for MultipleHostAccess tip)
You can use this:
Get-Datastore | Get-View | Select-Object  @{n="Name";e={$_.Name}}, @{n="San_Nas";e={$_.Summary.MultipleHostAccess}}

Name San_Nas
---- -------
NFS_VOL2 True
LOCAL_ESX01 False
NFS_VOL1 True
LOCAL_ESX02 False
LOCAL_ESX03 False



Solution 3: use Vendor / Model SCSILun informations from VMHost get-view
Get-VMHost | Get-View | Foreach-Object { $vmhost=$_.Name; $_.Config.StorageDevice.ScsiLun |  Select-Object @{n="Hostname";e={$vmhost}},@{n="Model";e={$_.Model}},@{n="Vendor";e={$_.Vendor}} }


Hostname Model Vendor
-------- ----- ------
esx01 LOGICAL VOLUME HP
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx01 SYMMETRIX EMC
esx02 RAID 5 DGC
esx02 SYMMETRIX EMC
esx02 SYMMETRIX EMC
esx02 RAID 5 DGC
esx03 LOGICAL VOLUME HP
esx03 2810XIV IBM
esx03 2810XIV IBM
esx03 2810XIV-LUN-0 IBM
esx03 2810XIV IBM



Example of SAN vendor/model
Vendor / Model
VMware / Block device
EMC / SYMMETRIX
IBM / 2810XIV

Example of Local storage
Vendor / Model
HP / LOGICAL VOLUME
DGC / RAID 5

6 comments:

JayWal said...

Hi Frank, great command. I've been trying to get a list of all VMs located in a datastore folder located in a datacenter but cant figure it out. Do you have any ideas?

VMWare view:
HOME-Inventory-Datastores.

Datacenter: DC1
FOlder:Folder1

In the contents of Folder1 I have a list of datastores. I want to know what VMs live on those datastores.

Ive tried several different commands. This is one:

Get-VM | where { $_.Name -ne (Get-datacenter DC1 | Get-Folder "Folder1" | Get-VM) }| Export-Csv -NoTypeInformation C:\file.csv


Its coming back with results not it has VMs from other folders.

Franck RICHARD said...

I"m not sure to understand exactly what you want. Is it something like this ?

Get-Folder -Name "myfolder" | Get-VMHost | Get-Datastore

result:
Name FreeSpaceMB CapacityMB
---- ----------- ----------
NFS_VOL1 155739 344460
NFS_VOL2 242186 344462
ESX1:storage1 115150 132096


Get-Folder -Name "myfolder" | Get-VMHost | Get-Datastore | Get-Vm

Name PowerState Num CPUs Memory (MB)
---- ---------- -------- -----------
LIN_91 PoweredOff 1 512
W2K3_62 PoweredOff 1 2048
Template-W2K8 PoweredOff 2 4096

JayWal said...

Hi Frank,

Thanks for the quick reply. This command works(Get-Folder -Name "FolderName" | Get-VMHost | Get-Datastore | Get-Vm
) for a folder in the Home-Inventory-Hosts and Clusters view(in vSphere) but not for a folder in Home-Inventory-Datastores view. In the Home-Inventory-Datastore view I have a Datacenter with subfolders. Each subfolder has a list of datastores. I want to know what VMs live on the datastores by folder name.

Thanks!

Franck RICHARD said...

$arrFolders = Get-Folder -Name "testDS" | Get-View
$arrDS = $arrFolders | ForEach-Object { $_.ChildEntity }
foreach ($ds in $arrDS) { Get-Datastore | Where-Object { $_.ExtensionData.Moref -eq $ds} }

result:
Name FreeSpaceMB CapacityMB
---- ----------- ----------
NFS_VOL1 155739 344460
ESX1:storage1 115150 132096

Franck RICHARD said...

then if you need to know all VM
on these datastore use these lines

$dsinfolder = foreach ($ds in $arrDS) { Get-Datastore | Where-Object { $_.ExtensionData.Moref -eq $ds} }

$arrVM = Get-VM
foreach ($vm in $arrVM) { $ads = $vm.ExtensionData.Datastore; foreach ($fds in $dsinfolder) { if ($ads -eq $fds.ExtensionData.Moref){ $vm } } }

result
Name PowerState Num CPUs Memory (MB)
---- ---------- -------- -----------
LIN_91 PoweredOff 1 512
W2K3_62 PoweredOff 1 2048
Template-W2K8 PoweredOff 2 4096

JayWal said...

Frank,

The last 2 commands looks like they worked. I need to verify the output but I randomly checked a few VMs from the output and they match the correct folder/datastore.

Thanks again!