VMware Cloud Community
MikePoe
Contributor
Contributor

Using Get-DataStore to check volume

Greetings all,

is there an easy way to check for the existence of a volume on a LUN prior to it being allocated using New-DataStore? I realize the command will fail if there is already a volume present, but I would like to check and log it first, and skip when not applicable. This is for a VMFS volume. Thanks.

0 Kudos
2 Replies
Herschelle
Enthusiast
Enthusiast

I have the same question. I tried looking at the Get-ScsiLun CmdLet to return all the visible luns to the host and tried to see if there was a property like there is on the Get-Datastore for Type or a link to a datastore. None that I could find.

Also tried seeing if I could link them some how by doing a comparison between the Get-ScsiLun back to the datastore instead like seeing if the datastore object had the scsilun information in it, again none that i could find.

I do not know how to use the SDK properly to find out this type of information, so am stuck too.

0 Kudos
ykalchev
VMware Employee
VMware Employee

Hi,

You can check for available volumes for VMFS datastore extents using QueryAvailableDisksForVmfs method of the HostDatastoreSystem SDK object. Then you can search the result using cannonical name to find out if the volume can be used by New-Datastore:

$pathToCheck = "mpx.vmhba0:C0:T1:L0"

$h =  Get-VMHost myHost
$hostSystem = $h | Get-View
$dsSystem = Get-View $hostSystem.ConfigManager.DatastoreSystem
$scsiDisk = $dsSystem.QueryAvailableDisksForVmfs($null)
foreach ($disk in $scsiDisk) {
  if ($disk.CanonicalName -eq $pathToCheck){
     New-Datastore -Name newDs -VMHost $h -VMFS -Path $pathToCheck
  }
}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
0 Kudos