VMware Cloud Community
drwoodberry
Contributor
Contributor

Adding new Datastore

I have been fighting the two posted sample codes for adding a new datastore to the ESX hosts. It seems that no matter what I do I get the error "Cannot validate the arguement on parameter 'Path'. It is either null or empty." My latest attempt is in the code below: I have some code commented out so you can see what other things I have tried. Any help would be great.

$Hosts = get-datacenter $datacenter -Server $sourceVI | Get-VMHost

Foreach ($line in $Hosts)

{

$iscsiHBA = Get-VMHostHBA -VMHost $line.Name -Type iSCSI

$iscsiHBA | New-IscsiHBATarget -Address 192.168.10.16 -Type send

Get-VMHostStorage $line.Name -RescanAllHba #-RescanVmfs

#$lunpath = (Get-ScsiLun -VMHost $line.Name -LunType disk | Get-ScsiLunpath)

$lunpath = Get-ScsiLun -VMHost $line.Name -LunType disk

New-Datastore -Vmfs -VMHost $line.Name -Path $lunpath.CanonicalName -Name iSCSI

}

0 Kudos
3 Replies
LucD
Leadership
Leadership

If you do

Get-Help New-Datastore -Examples

you'll see in Example 2 that you need the LunPath property returned by Get-ScsiLunPath.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
drwoodberry
Contributor
Contributor

With that being said, I have tried the below code with no luck.

$lunpath = Get-ScsiLun -VMHost $line.Name -LunType disk | Get-ScsiLunpath New-Datastore -Vmfs -VMHost $line.Name -Path $lunpath.LunPath -Name iSCSI

Using that code the error generated is "Get-ScsiLunPath : Cannot bind parameter 'ScsiLun'. Cannot convert the "New-Data store" value of type "System.String" to type "VMware.VimAutomation.Types.Host.ScsiLun".

Again, thanks for your help.

0 Kudos
drwoodberry
Contributor
Contributor

I have resolved this with the following code for those who may need help: This is specific to Netapp Storage.

$lunpath = Get-ScsiLun -VMHost $line.Name -LunType disk | Where{ $_.Vendor -match "NETAPP"}

  1. Pass the LUN's canonical name to New-Datastore

Get-VMHost $line.Name | New-Datastore -Vmfs -Path $lunpath.CanonicalName -Name VMStorage

0 Kudos