Adding a new volume to an ESX host using Powershell

As I have a script already to create a new volume via Powershell, I wanted to extend it to add a new volume (datastore). The following function will do that:

Function vmAddStorage
{
    param ([string]$server, [string]$volname)
    #Example usage - vmAddStorage esxhost myNewVolume
    $myhost = get-vmhost $server
    $myhost | get-vmhoststorage -RescanAllHba
	
	$lunpath = Get-VMHost | Get-ScsiLun | Where { $_.Vendor -match "EQLOGIC"}
	new-datastore -vmfs -vmhost $myhost -path $lunpath.CanonicalName -Name $volname
	
    $myhost | get-vmhoststorage -RescanAllHba
}

This is for Equallogic storage, but you could adapt it for use with other storage vendors. to know what to use in the $lunpath line, you could run

Get-VMHost | Get-ScsiLun | format-list

Then look for the Vendor property. I ran this against ESXi 4.1 so far using version 1.0 of the pssnapin (vmware.viautomation.core).

Advertisements

Leave a comment

Filed under Equallogic, Powershell, VMware

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s