Loading

×Sorry to interrupt
CSS Error

Refresh

Cookie Preference Center

General Information on cookies

When you visit our website, we use cookies to ensure that we give you the best experience. This information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies by clicking on the different category headings to find out more and change your settings. However, blocking some types of cookies may impact your experience on the site and the services we are able to offer. Further information can be found in our

Cookie Policy.

Strictly Necessary

Strictly Necessary

Always Active

Strictly Necessary

Strictly necessary cookies are always enabled since they are essential for our website to function. They enable core functionality such as security, network management, and website accessibility. You can set your browser to block or alert you about these cookies, but this may affect how the website functions. For more information please visit www.aboutcookies.org or www.allaboutcookies.org.

Cookie Details‎

Performance

Performance

Performance

Performance cookies are used to analyze the user experience to improve our website by collecting and reporting information on how you use it. They allow us to know which pages are the most and least popular, see how visitors move around the site, optimize our website and make it easier to navigate.

Cookie Details‎

Please confirm your settings by refreshing the page.

Functional

Functional

Functional

Functional cookies help us keep track of your past browsing choices so we can improve usability and customize your experience. These cookies enable the website to remember your preferred settings, language preferences, location and other customizable elements such as font or text size. If you do not allow these cookies, then some or all of these services may not function properly.

Cookie Details‎

Advertising

Advertising

Advertising

Advertising cookies are used to send you relevant advertising and promotional information. They may be set through our site by third parties to build a profile of your interests and show you relevant advertisements on other sites. These cookies do not directly store personal information, but their function is based on uniquely identifying your browser and internet device.

Cookie Details‎

Advertising Cookies

Consent Leg.Interest

Select All Vendors

Select All Vendors

Select All Hosts

Select All

Clear Filters

Information storage and access

Apply

Confirm My Choices Reject All Allow All

My Subscriptions

Loading

Knowledge Base

Managing storage using PowerCLI (1028368)

Last Updated: 9/28/2010Categories: Total Views: 33895Language:
English

3 like this article

Subscribe to get an email
newsletter with new updates

3 people found this helpful Please provide article feedback:

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

Detectable by VMware SkylineTM

Actions

Copy

link to clipboard
copied!

Print

Language:
English

Attachments

Additional Resources

KB
•
End Of General Availability of the Free vSphere Hypervisor (ESXi 7.x and 8.x) (2107518)

KB
•
Download and Install VMware Fusion (2014097)

Results 1-2 of 2

Ask The Community

Get answers quickly from VMware experts in the community

Post Subject

CONTINUE IN COMMUNITIES

Related Products:

VMware vSphere PowerCLI

VMware vSphere

Related Versions:

VMware vSphere PowerCLI 4.0

Take Our Survey

Support Assistant