Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

FIND FREE OR UNASSIGNED STORAGE LUN DISKS ON VMWARE ESXI SERVER

This is one of my small script. And I use it to find free or unassigned unforrmatted LUNs/Disks on Esxi server. When Lun or disk from storage (most probably remote) assigned and presented to Esxi server, this LUN doesn't have any partition, and unformatted as a raw disk, This is visible when you try to add new datastore. Same list I can pull using VMware Powercli script. Script is combination of two cmdlets Get-Scsilun and Get-Datastore and processes data.

This require VMware powercli installer or module, follow this article to setup it VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP. Login to esxi or vCenter with Connect-VIServer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function Get-FreeEsxiLUNs {
    ##############################
    #.SYNOPSIS
    #Shows free or unassigned SCSI LUNs/Disks on Esxi
    #
    #.DESCRIPTION
    #The Get-FreeEsxiLUNs cmdlet finds free or unassigned SCSI LUNs/Disks on VMWare Esxi server. Free or unassigned disks are unformatted LUNs and need to format VMFS datastore or use as RDM (Raw Device Mapping)
    #
    #.PARAMETER Esxihost
    #This is VMware Esxi host name
    #
    #.EXAMPLE
    #Get-FreeEsxiLUNs -Esxihost Esxi001.vcloud-lab.com
    #
    #Shows free unassigned storage Luns disks on Esxi host name Esxi001.vcloud-lab.com
    #
    #.NOTES
    #http://vcloud-lab.com
    #Written using powershell version 5
    #Script code version 1.0
    ###############################

    [CmdletBinding()]
    param(
        [Parameter(Position=0, Mandatory=$true)]
        [System.String]$Esxihost
    )    
    Begin {
        if (-not(Get-Module vmware.vimautomation.core)) {
            Import-Module vmware.vimautomation.core
        }
        #Connect-VIServer | Out-Null
    }
    Process {
        $VMhost = Get-VMhost $EsxiHost
        $AllLUNs = $VMhost | Get-ScsiLun -LunType disk
        $Datastores = $VMhost | Get-Datastore
        foreach ($lun in $AllLUNs) {
            $Datastore = $Datastores | Where-Object {$_.extensiondata.info.vmfs.extent.Diskname -Match $lun.CanonicalName}
            if ($Datastore.Name -eq $null) {
                $lun | Select-Object CanonicalName, CapacityGB, Vendor        
            } 
        }
    }
    End {}
}

#Get-FreeEsxiLUNs -Esxihost <Esxi001.vcloud-lab.com>

After login, copy paste above script on powershell console (powercli), Run new function command with Get-FreeEsxiLUNs -Esxihost <VcenterEsxi_IP_FQDN>, It show the list of free luns and I have only one at the moment.

vmware vsphere powercli connect-viserver get-freeEsxiLUNs, shows or find free esxi lun remote storage disk

New updated version of script is available on GitHub.com.

Useful Articles
Adding and sharing RDM disk to multiple VMs in VMware step by step

Go Back

Comment

Blog Search

Page Views

11274228

Follow me on Blogarama