alex_aldo - Fotolia

Tip

Manage a multitude of VMware datastores using PowerCLI

Discover how you can use PowerCLI to boost your storage by monitoring and managing VMware datastores across multiple hosts. This tool has many advantages over the typical GUI.

You can manage singular datastores in VMware vSphere through the vSphere Web Client, the HTML5 client or the GUI, but you might find PowerCLI more efficient when working with multiple hosts or datastores.

PowerCLI has many advantages over a traditional GUI in vSphere. For instance, you can quickly view VMware datastore information across many hosts with PowerCLI due to its automation capabilities, which are backed by PowerShell.

Get datastore information

You can directly access ESXi hosts with PowerCLI, but you can also connect to vCenter, which gives you access to any host associated with the vCenter instance you connect to. In addition, PowerCLI and PowerShell now work across platforms, so you can use PowerCLI on a Mac.

To start, connect to vCenter with Connect-ViServer:

Connect to vCenter

Use the Get-Datastore command in PowerCLI to display datastore specifics. Piping this cmdlet to show all of the properties of a VMware datastore displays a lot of data, such as the IP, path, authentication and capacity information.

Get-Datastore command

PowerCLI provides fast, instant reporting. Here, you can get a report on every datastore in your vCenter and choose the property's name, type, capacity and free space:

PowerCLI Get-Datastore

Add a datastore

Add a VMware datastore to ESXi hosts by using the New-Datastore cmdlet. You can see the available parameters by typing a dash and hitting the Tab key twice:

New-Datastore cmdlet

To add a Network File System datastore, specify the –Nfs switch in your cmdlet, along with the path and -nfshost parameters:

Nfs switch

Modify a datastore

The Set-Datastore cmdlet enables you to modify a VMware datastore in multiple ways, such as renaming a datastore or putting the datastore into maintenance mode.

To rename a datastore, simply pipe the Get-Datastore cmdlet to Set-Datastore, and specify the new name via the –Name parameter:

-Name parameter

You can also change multiple datastores at once. For example, you can take every datastore in your vCenter and set storage I/O to true:

Set to true

Putting a datastore in maintenance mode and setting the parameter –EvacuateAutomatically will move all VMs located on the datastore to another datastore via vMotion. This means you can perform maintenance on multiple datastores in one action.

For example, you can take all of the datastores with the name starting with New_York by using a wildcard and pipe the output to Set-Datastore. This specifies that you want to put them in maintenance mode and evacuate the VMs.

wildcard

Remove a datastore

You can easily remove datastores from ESXi hosts using Remove-Datastore. The parameters for Remove-Datastore are similar to the other cmdlets, as you have to specify the name of the datastore and the host to remove it from.

For example, you can remove the datastore Test-1 from host Testhost-1:

remove datastore

In a more complex scenario, you might remove the same datastore from any host starting with Test by using a ForEach loop in PowerCLI:

ForEach loop

Because PowerCLI is built on PowerShell, its automation capabilities provide you with easy methods to accomplish many tasks instantaneously. In addition, PowerCLI provides you with valuable reporting and discovery abilities, especially for large virtual environments.

Next Steps

Learn to properly scale your datastores for vSphere

Use PowerCLI to deploy a VM from a template

Create, modify and maintain a VMFS Datastore

Dig Deeper on VMware ESXi, vSphere and vCenter