VMware Cloud Community
nmbgdc
Enthusiast
Enthusiast
Jump to solution

How to find the free remote LUN ( not the local disk ) on esxi using powercli to create datastore?

Hi Guys,

I want to create the data store only on based on the available free disk which is remote LUN from storage and not on the local storage.

here are few google command i tried but list is getting listed with local disk also

this command list all the free disk ( including remote & local )

$disk_list=(get-view (get-vmhost -name $vmhost | Get-View ).ConfigManager.DatastoreSystem).QueryAvailableDisksForVmfs($null)

is there way to only get including remote ?

FYI--

based on the list of the disk will create loop to create the datastore hence the requirement..

Thanks

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Hi Luc

Now this how i have done it.. this script will create the Datastore on free available disk for VMFS datastore only, it will not list the LocalDisk.

param(

[String] $vcenter_fqdn,

[String] $vcenter_username,

[String] $vcenter_password,

[String] $cluster_name,

[String] $datastore_name

)

Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password

$clustername = get-cluster $cluster_name

$vmhost = Get-Cluster $clustername | Get-VMhost | Select -First 1

$disk_list=(get-view (get-vmhost -name $vmhost | Get-View ).ConfigManager.DatastoreSystem).QueryAvailableDisksForVmfs($null)

$free_disk=$disk_list | Where-Object{$_.Ssd -eq "true"}

$disk_ca=($free_disk).CanonicalName

$free_disk | foreach{

$i++

$ds_name=$datastore_name

New-Datastore -vmhost $vmhost -Name $ds_name -Path $disk_ca -Vmfs -FileSystemVersion 6

}

View solution in original post

Reply
0 Kudos
7 Replies
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Even I tried below command--but list all the disk used & unused including local disk

Get-SCSILun -VMhost 192.168.200.136 -LunType Disk | Select CanonicalName,Capacity

CanonicalName                        Capacity

-------------                        --------

naa.6f47acc100000000653874730000005a

naa.6f47acc100000000653874730000005b

mpx.vmhba0:C0:T0:L0

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try my function in Find Free SCSI LUNs?

It uses the API to find free LUNs that are available to create a VMFS datastore.

I'm not sure what you mean by local and remote LUNs.

Or do you mean a LUN over a specific HBA?
An another option is to find the free LUNs on all the ESXi nodes, and then only use a LUN that is visible on all ESXi nodes.

Or you can use the IsLocal property on the LUNs returned by esxcli

$esxcli = Get-EsxCli -VMHost MyEsx -V2

$esxcli.storage.core.device.list.Invoke() |

where{-not $_.IsLocal} | Select Device,DisplayName


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Hi Thanks for your reply--

Local i mean the disk on which we installed OS, that is also getting listed as disk..

and i tried your command but not getting any output for command red in color.

$esxcli = Get-EsxCli -VMHost MyEsx

$esxcli.storage.core.device.list.Invoke() |

where{-not $_.IsLocal} | Select Device,DisplayName

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, I forgot to copy the V2 switch


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Hi Thanks for your reply..

I tried your command it did not work and dont know why here is the screenshot

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You didn't use the V2 switch

$esxcli = Get-EsxCli -VMHost MyEsx -V2


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Hi Luc

Now this how i have done it.. this script will create the Datastore on free available disk for VMFS datastore only, it will not list the LocalDisk.

param(

[String] $vcenter_fqdn,

[String] $vcenter_username,

[String] $vcenter_password,

[String] $cluster_name,

[String] $datastore_name

)

Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password

$clustername = get-cluster $cluster_name

$vmhost = Get-Cluster $clustername | Get-VMhost | Select -First 1

$disk_list=(get-view (get-vmhost -name $vmhost | Get-View ).ConfigManager.DatastoreSystem).QueryAvailableDisksForVmfs($null)

$free_disk=$disk_list | Where-Object{$_.Ssd -eq "true"}

$disk_ca=($free_disk).CanonicalName

$free_disk | foreach{

$i++

$ds_name=$datastore_name

New-Datastore -vmhost $vmhost -Name $ds_name -Path $disk_ca -Vmfs -FileSystemVersion 6

}

Reply
0 Kudos