VMware Cloud Community
vin01
Expert
Expert
Jump to solution

To find unmounted/Detached Luns in a datacenter

Hello techies

Is it possible to find unmounted and detached luns in a datacenter for VMhost hba level.

Using FC SAN storage.

In my scenario

1.On a datacenter many storage luns are mapped to more that one cluster or for a cluster and a standalone hosts in datacenter.--- How to get LunNNA  with Mapped cluster name, Host IP

2.For some luns VMs are running on only one cluster but that lun is mapped to many clusters or standalone hosts in datacenter.---How to get LunNNA with cluster name or standalone hosts where vms are running and Cluster name  or standalone hosts where Lun only mapped but no vms are running.

3.Some Luns are unmounted and detached on the esxi hosts but not removed from storage end.-- How to get that Lun NNA and cluster name and Host IP or standalone hosts IP where LUN is unmounted and detached but not removed from storage.

Regards Vineeth.K
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

&

  $esx = Get-VMHost 10.50.44.38 

  foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel" | where {$_.Status -eq "online"} )){ 

    $luns = Get-ScsiLun -Hba $hba -LunType "disk" -ErrorAction SilentlyContinue  

    $luns | Select @{N="HBA";E={$hba.Name}},RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E=

        if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"

        else

            Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name 

        } 

      }},

      @{N="Datacenter"; e={(Get-Datacenter -VMHost $_.VMHost).name}},Vendor,

      @{N="OperationalState";E={$_.ExtensionData.OperationalState}} | 

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0], 

      [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))}, 

      {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))}, 

      {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))} 

  } 

}    


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

View solution in original post

0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

Would the script in my LUN report – datastore, RDM and node visibility post help ?


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

0 Kudos
vin01
Expert
Expert
Jump to solution

No Luc, I already tried this..Any other hope .. They are 5000 Luns in datacenter..Its to hard to check manually.

I generally used this to find datastore name and mapped cluster details, can you help me on  Point 2 and 3 i written above post.

Get-Datastore "datastore1"  | % {

$ds=$_; Get-VMHost -Datastore $ds |

select @{N="Datastore name";E={$ds.Name}},

@{N="NAA"; E={if($ds.Type -like "VMFS"){[String]::join(',',($ds.ExtensionData.Info.Vmfs.Extent|%{$_.Diskname}))}}},

Name,

@{N="cluster";E={$_|Get-Cluster}},

version

}

Output :

Datastore name :datastore1 "datastore1"

NAA            : naa.60060160ea932400c28b845f8fb4e211

Name           : 10.xx

cluster        : testcluster

Version        : 5.0.0

Datastore name : datastore1 "datastore1"

NAA            : naa.60060160ea932400c28b845f8fb4e211

Name           : 10.xx.xx

cluster        : testcluster

Version        : 5.0.0

Datastore name : datastore1

NAA            : naa.60060160ea932400c28b845f8fb4e211

Name           : 10.xx

cluster        : testcluster

Version        : 5.0.0

============

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

Hi Luc

How to include 'Operational State' Like whether Lun is Mounted or Unmounted in the below script.

get-vmhost |Get-ScsiLun -LunType disk |

Select RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E={

        if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

        else{

            Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

        }

      }},Vendor,OperationalState |

Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

[int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

{[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

{[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

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

Output :

RuntimeName      : vmhba36:C0:T12:L33

CanonicalName    : naa.6006016002da27009496b5317a3ee011

CapacityGB       : 150

VMHost             : 10.xx.xx.xx

Cluster              :  UAT

Vendor              : DGC

OperationalState :  ??? (Missing)

==============

For better understand I need 'Operational State' which is shown in vcenter stoarge adapters Devices tab

operational state.png

Regards Vineeth.K
0 Kudos
Wh33ly
Hot Shot
Hot Shot
Jump to solution

Maybe these functions are useful for you:

Datastore Mount/Unmount Detach/Attach functions

0 Kudos
vin01
Expert
Expert
Jump to solution

Not Exactly..The script i given is ok but im missing only 'Operational Status' Like Lun mounted or unmounted which we find in vcenter.

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

get-vmhost |Get-ScsiLun -LunType disk | 

Select RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E=

    if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"

    else

        Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name 

    }}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}} | 

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0], 

    [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))}, 

    {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))}, 

    {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}  


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

0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks LucSmiley Happy That works perfectly..But here I missed a small information..

For a host there are two active HBAs and luns are mapped to two HBAs but i'm getting information of only first HBA.(like RuntimeName : vmhba1:C0:T10:L0) here missing info of vmhba2. Even i changed script as below.

Get-VMHost 10.50.44.38 |Get-VMHostHba -Type FibreChannel | where {$_.Status -eq "online"} |Get-ScsiLun -LunType disk |

Select RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E={

    if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

    else{

        Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

    }}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}} |

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

    [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

    {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

    {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid that is an "issue" in the Get-ScsiLun cmdlet.

Even though you specify another HBA on the Hba parameter, the returned RuntimeName always contains the same HBA name.


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

0 Kudos
vin01
Expert
Expert
Jump to solution

I think soo:smileyconfused:

Even I tried like this but it still showing only vmhba1 output no second active output..

$hba= Get-VMHost 10.50.44.38 |Get-VMHostHba -Type FibreChannel | where {$_.Status -eq "online"}

$hba |Get-ScsiLun -LunType disk |Select RuntimeName,CanonicalName,CapacityGB,VMHost,

@{N="Cluster";E={

    if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

    else{

        Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

    }}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}} |

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

    [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

    {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

    {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

=====

OutPut :

detacherror.JPG

Missing vmhba2 output

======================

If I tried like this it throwing different error, Can you corrent me on the below script or by this way can get both activity HBA output

foreach ($Datacenter in Get-Datacenter) {

foreach ($vmHost in @($Datacenter |Get-VMHost)) {

foreach ($hba in @($vmHost | Get-VMHostHba -Type FibreChannel |where {$_.Status -eq "online"} )) {

foreach ($ScsiLun in @($hba | Get-ScsiLun -LunType disk)) {

$objhba = " " | select RuntimeName,CanonicalName,CapacityGB,VMHost,

@{N="Cluster";E={

    if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

    else{

        Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

    }}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}}

  # Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

   #[int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

   #{[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

   #{[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

    $objhba.runtimename =$RuntimeName.name

    $objhba.CanonicalName =$CanonicalName.name

    $objhba.CapacityGB =$CapacityGB.name

    $objhba.VMHost =$vmHost.name

    $objhba.vendor =$vendor.name

    }

    }

    }

    }

==========

Output :

detacherror1.JPG

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

Hi Luc

Can you correct me on the above script.

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

Hi

Can Some one Help me to link the script

Get-VMHost 10.50.44.38 | %{

$esxImpl = $_

$esx = Get-View $esxImpl

$esxImpl | Get-VMHostHba -Type FibreChannel |where {$_.status -eq "online"} | %{

$hba = $_

Get-ScsiLun -Hba $hba | %{

$lun = $_

$row = "" | Select

======Need to integrate Below script ==========

|Select RuntimeName,CanonicalName,CapacityGB,VMHost,

@{N="Cluster";E={

    if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

    else{

        Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

    }}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}} |

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

    [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

    {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

    {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

}

}

}

Expected output:

================

RuntimeName      : vmhba0:C0:T7:L12

CanonicalName    : naa.60060160ea932400c839e460e1ace211

CapacityGB       : 150

VMHost           : 10.50.44.38

Cluster          : Stand alone host

Vendor           : DGC

OperationalState : ok

RuntimeName      : vmhba1:C0:T7:L13

CanonicalName    : naa.60060160ea9324007a381019edace211

CapacityGB       : 600

VMHost           : 10.50.44.38

Cluster          : Stand alone host

Vendor           : DGC

OperationalState : ok

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks for your support LucSmiley Happy Some How I managed to rewrite the code to get both active HBA output (I mean vmhba1 & vmhba2).

Here I'm missing Datacenter Name can you correct me..

Code Used :

& {

$esx = Get-VMHost 10.50.44.38

  foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel" | where {$_.Status -eq "online"} )){

    $luns = Get-ScsiLun -Hba $hba -LunType "disk" -ErrorAction SilentlyContinue

    $luns | Select @{N="HBA";E={$hba.Name}},RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E={

        if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"}

        else{

            Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name

        }

      }},@{N="Datacenter"; e={($_.VMHost.ExtensionData.Parent | Get-Datacenter).name}},Vendor,@{N="OperationalState";E={$_.ExtensionData.OperationalState}} |

Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],

[int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},

{[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},

{[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

   

  }

OutPut :

============

HBA              : vmhba1

RuntimeName      : vmhba1:C0:T7:L10

CanonicalName    : naa.60060160ea9324008899116621a7e211

CapacityGB       : 600

VMHost           : 10.50.44.38

Cluster          : Stand alone host

Datacenter       :

Vendor           : DGC

OperationalState : ok

===

HBA              : vmhba2

RuntimeName      : vmhba1:C0:T10:L0

CanonicalName    : naa.6005076802810bd6c800000000000096

CapacityGB       : 1200

VMHost           : 10.50.44.38

Cluster          : Stand alone host

Datacenter       :

Vendor           : IBM

OperationalState : ok

Regards Vineeth.K
LucD
Leadership
Leadership
Jump to solution

Try like this

&

  $esx = Get-VMHost 10.50.44.38 

  foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel" | where {$_.Status -eq "online"} )){ 

    $luns = Get-ScsiLun -Hba $hba -LunType "disk" -ErrorAction SilentlyContinue  

    $luns | Select @{N="HBA";E={$hba.Name}},RuntimeName,CanonicalName,CapacityGB,VMHost,@{N="Cluster";E=

        if($_.VMHost.ExtensionData.Parent.Type -ne "ClusterComputeResource"){"Stand alone host"

        else

            Get-view -Id $_.VMHost.ExtensionData.Parent | Select -ExpandProperty Name 

        } 

      }},

      @{N="Datacenter"; e={(Get-Datacenter -VMHost $_.VMHost).name}},Vendor,

      @{N="OperationalState";E={$_.ExtensionData.OperationalState}} | 

    Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0], 

      [int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))}, 

      {[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))}, 

      {[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))} 

  } 

}    


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

0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks Luc Smiley Happy That works perfectly..

Regards Vineeth.K
0 Kudos