Monday, January 29, 2018

How to use PowerCLI to list Device ID, Mounted URL of Datastores in VMware

Here is the PowerCLI one-liner command to find the Datastore Name, Mounted URL and Device ID in your vSphere Environment.
Assume you've installed VMware PowerCLI. You can download the PowerCLI 6.5.0R1 here.

1) If the vCenter is not connected, then connect to vCenter first.
Connect-VIServer -Server  <yourVCenterIP> -Credential (Get-Credential)

2) Type the following (copy/paste) command to list Datastore Info of currently connected vCenter.
Get-Datastore |  foreach { $_ | Add-Member NoteProperty "URL" $_.extensiondata.info.url -PassThru | Add-Member NoteProperty "DeviceID" $_.extensiondata.info.vmfs.extent.diskname -PassThru } | select Name,DeviceID,URL

3) If you want to export the result to csv file, then skip step-2 and use the following command.
Get-Datastore |  foreach { $_ | Add-Member NoteProperty "URL" $_.extensiondata.info.url -PassThru | Add-Member NoteProperty "DeviceID" $_.extensiondata.info.vmfs.extent.diskname -PassThru } | select Name,DeviceID,URL | Export-Csv -NoType DatastoreDeviceInfo.csv