Search the VMware Knowledge Base (KB)
View by Article ID

Managing storage using PowerCLI (1028368)

  • 2 Ratings

Purpose

vSphere PowerCLI can be used to automate the different virtual machine tasks. vSphere PowerCLI provides easy-to-use C# and PowerShell interface to VMware vSphere APIs. 
 
In PowerShell, commands are called cmdlets, a term used in this article.
 
This article provides an overview of the different cmdlets that are available to perform these tasks:
  • Collecting information about the storage connected to the ESX/ESXi hosts
  • Working the datastores
 

Resolution

Collecting information about the storage connected to the ESX/ESXi hosts

This section provides information about the commands that can be used to collect information about the storage that is used. The commands can be customized to retrieve the details about specific ESX/ESXi hosts by using the Get-Datacenter, Get-Cluster or Get-VMhost options.
 
In the example, we use Get-VMHostStorage cmdlet to collect the Storage details (ESX host IP, Datastore Name, Software iSCSI status, Runtime Name, NAA.ID) about all the ESX hosts in the cluster:
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-VMHost | Get-VMHostStorage | Format-List *
 
VMHost                     : 10.112.96.17
FileSystemVolumeInfo       : {datastore1 (2), vCloud-1, vCloud-0}
SoftwareIScsiEnabled       : True
ScsiLun                    : {HostSystem-ha-host/mpx.vmhba3:C0:T0:L0, HostSystem-ha-host/naa.600508b1001037383941424344450500,
 
To retrieve the details about the CanonicalName(naa.id), Raid Level, LunType, ConsoleDeviceName, Capacity, MultipathingPolicy, you can use this command:
 
Note: The Format-List option is used to get the details about all the properties available for Get-ScsiLun object.
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-VMHost | Get-ScsiLun -LunType disk | ft -autosize
 
CanonicalName                        ConsoleDeviceName                                        LunType CapacityMB MultipathPolicy
-------------                        -----------------                                        ------- ---------- ---------------
naa.600508b1001037383941424344450500 /vmfs/devices/disks/naa.600508b1001037383941424344450500 disk        279964 Fixed
naa.60060160582017005c0a006277b6df11 /vmfs/devices/disks/naa.60060160582017005c0a006277b6df11 disk         51200 MostRecentlyUsed
naa.60060160582017005d0a006277b6df11 /vmfs/devices/disks/naa.60060160582017005d0a006277b6df11 disk         51200 MostRecentlyUsed
 
vSphere PowerCLI provides Get-Datastore cmdlets to retreive the details about the Datastore. This command can be further customized to get the datastore details at the Datacenter, Cluster, Host and Virtual Machine level:
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get- Datastore
 
Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
vCloud-1                                 18925           50944

Working with Datastores

This section discuss the cmdlets provided by vSphere PowerCLI to manage the existing storage.
 
Remove-Datastore removes the specified datastores from their locations.
 
Note: The cmdlet permanently deletes the content of the removed datastores. If -Confirm:$true parameter is used, the cmdlet asks for confirmation before running. If -Confirm:$false is used, the cmdlet runs without asking for user confirmation.
 
For example:
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Remove-Datastore -Datastore vCloud-0 -VMHost 10.112.96.17 -Confirm:$false
 
vSphere PowerCLI provides New-Datastore to create a new VMFS/NFS/iSCSI datastores. For example, to create a new VMFS Datastore:
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> New-Datastore -Name vCloud-0 -Path naa.60060160582017005c0a006277b6df11 -Vmfs
 
Name: vCloud-0
Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
vCloud-0                                 50425           50944

 
For more information on creating a new datastore using iSCSI, see Work with Host Storages and iSCSI HBA Devices in the vSphere PowerCLI Administration Guide. 
 
Note: If you receive errors that the specified path is in user or not available, connect to the ESX/ESXi host directly using vSphere PowerCLI and then run the command. 
 
vSphere PowerCLI also provides an option to rescan all the HBA's and VMFS volumes on all the ESX/ESXi hosts in the inventory:
 
[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs | ft -autosize
 
Id                              SoftwareIScsiEnabled
--                              --------------------
HostStorageSystem-storageSystem False

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 2 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.

What can we do to improve this information? (4000 or fewer characters)




Please enter the Captcha code before clicking Submit.
  • 2 Ratings
Actions
KB: