PowerCLI script to list VMFS,RDM and Free LUNs in a cluster

Its always a time consuming job to find out the LUN is FREE, RDM or VMFS. The following script will help to get the details of LUNs from hosts in a cluster and will tell us the LUN is VMFS, RDM or FREE.

If the LUN is an RDM, we can see on which VM RDM is mapped. And if the LUN has VMFS volume, the datastore name will be displayed. Also the script provides the details like LUN number, Capacity and naa id (Canonical Name).

The CSV file that is produced by the script looks like this. In this example cluster has four hosts (esx1,esx2,esx3 and esx4), four LUNs (0,1,2 and 13) are shared among them.

disk-details1

You can see there are four values for TYPE.

1. VMFS :- VMFS volume (datastore)

2. RDM :- Raw Device Map(RDM) LUN connected to a VM. We can see the corresponding VM in VMname column.
3. FREE :- The LUNs which are free for creating VMFS Datastores or RDMs.
4. UNKNOWN :- On two cases UNKNOWN will be shown.
a.  the LUNs which are presented as RDM on other host. In the example, LUN 13 is an RDM on virtual machine “TestVM1” running on host “esx1”. Hence LUN 13 will shown as UNKNOWN on other hosts in the cluster.
b. Script couldn’t find whether the LUN is VMFS, RDM or Free.

-SD

  • Rob

    Thanks for the great post Sree!

  • noto777

    How can this be modified to also display the multipath policy of the lun?

  • Crakk Stuh

    Thank you so much, saved a lot of time. Big ups from Switzerland

  • Aono Light

    Hi, can you please edit the script so that it only shows FREE space?

    -Thanks

  • Rothweiler

    I’m not finding something here…. I am getting:

    Method invocation failed because [System.Object[]] doesn’t contain a method named ‘LastIndexof’.
    At D:PowerCLIScriptsGetLUNDetails.ps1:52 char:103
    + $object | Add-Member -Name ‘LUN’ -MemberType Noteproperty -Value $rnName.Substring($rnName.LastIn
    dexof <<<< ("L")+1)
    + CategoryInfo : InvalidOperation: (LastIndexof:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    Same results if I invoke against a VSphere server or against an ESX host (PowerCLI 5.5 Release 1 against ESX 5.5, 5.1, & .4.1 and vCenter 5.5)
    I am running PowerCLI as Administrator on Win2008.

    • Martin Norman

      I found that I had to alter line 52 from:

      $object | Add-Member -Name ‘LUN’ -MemberType Noteproperty -Value $rnName.Substring($rnName.LastIndexof(“L”)+1)

      to:
      $object | Add-Member -Name ‘LUN’ -MemberType Noteproperty -Value $rnName[0].Substring($rnName[0].LastIndexof(“L”)+1)
      because $rnName was returning 2 values and not one per RDM/datastore.

      Hope that helps 🙂

  • tapan dewanjee

    I am new to script.. getting below errors. please help and tell me what changes need to be done on the script to run it on my environment.

    Get-Cluster : 1/16/2015 12:03:10 PM Get-Cluster Cluster with name ‘US
    A-XGI’ was not found using the specified filter(s).
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:65 char:21
    + $Hosts = Get-Cluster <<<< $clusterName | Get-VMHost | select -ExpandProperty
    Name
    + CategoryInfo : ObjectNotFound: (:) [Get-Cluster], VimException
    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
    utomation.ViCore.Cmdlets.Commands.GetCluster

    Collecting Datastore details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:71 char:17
    + get-vmhost -Name <<<< $vmHost | Get-Datastore | % {
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting RDM Disk details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:77 char:17
    + get-vmhost -Name <<<< $vmHost | Get-VM | Get-HardDisk -DiskType "RawPhysical
    ","RawVirtual" | % {
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting Free SCSI LUN(Non-RDM/VMFS) details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:83 char:28
    + (get-view (get-vmhost -name <<<< $vmHost | Get-View ).ConfigManager.Datastor
    eSystem).QueryAvailableDisksForVmfs($null) | %{
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting details of Unallocated LUNs from host ….
    Get-ScsiLun : Cannot validate argument on parameter 'VmHost'. The argument is n
    ull or empty. Supply an argument that is not null or empty and then try the com
    mand again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:89 char:20
    + Get-ScsiLun -VmHost <<<< $vmHost | %{
    + CategoryInfo : InvalidData: (:) [Get-ScsiLun], ParameterBinding
    ValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.Host.GetScsiLun

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:98 char:25
    + $global:LUNDetails.Clear <<<< ()
    + CategoryInfo : InvalidOperation: (Clear:String) [], RuntimeExce
    ption
    + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:99 char:25
    + $global:LUNDetTemp.Clear <<<< ()
    + CategoryInfo : InvalidOperation: (Clear:String) [], RuntimeExce
    ption
    + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:106 char:26
    + $global:LUNDetFinal.Clear <<<
    .RDM_script.ps1

    Name Port User
    —- —- —-
    13.120.206.19 443 XRXNAUSWU53299
    Get-Cluster : 1/16/2015 12:05:01 PM Get-Cluster Cluster with name ‘US
    A-0300-XGI-LAB-CLU001’ was not found using the specified filter(s).
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:65 char:21
    + $Hosts = Get-Cluster <<<< $clusterName | Get-VMHost | select -ExpandProperty
    Name
    + CategoryInfo : ObjectNotFound: (:) [Get-Cluster], VimException
    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
    utomation.ViCore.Cmdlets.Commands.GetCluster

    Collecting Datastore details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:71 char:17
    + get-vmhost -Name <<<< $vmHost | Get-Datastore | % {
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting RDM Disk details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:77 char:17
    + get-vmhost -Name <<<< $vmHost | Get-VM | Get-HardDisk -DiskType "RawPhysical
    ","RawVirtual" | % {
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting Free SCSI LUN(Non-RDM/VMFS) details from host ….
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:83 char:28
    + (get-view (get-vmhost -name <<<< $vmHost | Get-View ).ConfigManager.Datastor
    eSystem).QueryAvailableDisksForVmfs($null) | %{
    + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingV
    alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.GetVMHost

    Collecting details of Unallocated LUNs from host ….
    Get-ScsiLun : Cannot validate argument on parameter 'VmHost'. The argument is n
    ull or empty. Supply an argument that is not null or empty and then try the com
    mand again.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:89 char:20
    + Get-ScsiLun -VmHost <<<< $vmHost | %{
    + CategoryInfo : InvalidData: (:) [Get-ScsiLun], ParameterBinding
    ValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.ViCore.Cmdlets.Commands.Host.GetScsiLun

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:98 char:25
    + $global:LUNDetails.Clear <<<< ()
    + CategoryInfo : InvalidOperation: (Clear:String) [], RuntimeExce
    ption
    + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:99 char:25
    + $global:LUNDetTemp.Clear <<<< ()
    + CategoryInfo : InvalidOperation: (Clear:String) [], RuntimeExce
    ption
    + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Object[]] doesn't contain a method nam
    ed 'Clear'.
    At C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIscriptsRDM_sc
    ript.ps1:106 char:26
    + $global:LUNDetFinal.Clear <<<< ()
    + CategoryInfo : InvalidOperation: (Clear:String) [], RuntimeExce
    ption
    + FullyQualifiedErrorId : MethodNotFound

  • Pingback: Script PowerCLI para listar VMFS y RDM en un Cluster()

  • PhilTaylor

    Hi Sreejesh, appreciate this is an old topic but this could be very useful for me!
    One question I have ref the script. I don’t have a cluster set up just a datacentre with 4 hosts. What amendments do i need so that the script isn’t looking for a cluster name? Many Thanks

  • Mamo

    How do I get the Folder details in the above script ?

    Please help