VMware Cloud Community
Virtualduty
Enthusiast
Enthusiast

script to pull only the unmounted storage device from ESXi

Hello Everyone !

I'm looking for script that can list all the unmounted storage devices from the ESXi host,

Description : I have unmounted the vmfs volumes under datstores tab, detached the luns under devices tab, however these devices have not been unpresented from the SAN yet. Can anyone help with script to pull out the list of these unmounted devices on csv file. Some thing like in below format. and the script should prompt for cluster name. Thanks in advance.

clusteresx hostNAAid

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Does this do the trick?

foreach($cluster in Get-Cluster){

    foreach($esx in Get-VMHost -Location $cluster){

        $esxcli = Get-EsxCli -VMHost $esx -V2

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

        where{$_.IsOffline} |

        Select @{N='Cluster';E={$cluster.Name}},

                @{N='VMHost';E={$esx.Name}}, Device

    }

}


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

Virtualduty
Enthusiast
Enthusiast

HI LucD

It lists the mounted LUNs as well, I am looking for something that lists only the unmounted LUNS

Reply
0 Kudos
Virtualduty
Enthusiast
Enthusiast

I tried below

&{foreach($cluster in Get-Cluster){

foreach($esx in Get-VMHost -Location $cluster){

$esxcli = Get-EsxCli -VMHost $esx -V2


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


where{$_.IsOffline} |


Select @{N='Cluster';E={$cluster.Name}},


='VMHost';E={$esx.Name}}, Device


='Vendor';E={$scsilun.Vendor}}

| Export-Csv report.csv -NoTypeInformation -UseCulture

But I don't see vendor type in the output

Reply
0 Kudos
Virtualduty
Enthusiast
Enthusiast

This worked,

I believe

 

where{$_.IsOffline}  is not valid value , I tried where{$_.Status -eq "off"} |, but thank you so much for all your help

&{foreach($cluster in Get-Cluster){

    foreach($esx in Get-VMHost -Location $cluster){

        $esxcli = Get-EsxCli -VMHost host.com -V2

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

        where{$_.Status -eq "off"} |

        Select @{N='Cluster';E={$cluster.Name}},

                @{N='VMHost';E={$esx.Name}},
                @{N='Vendor';E={$_.Vendor}}, Device, Status
              
                }
}}| Export-Csv report.csv -NoTypeInformation -UseCulture 

Reply
0 Kudos
LucD
Leadership
Leadership

Glad you found it.

Yes, those flags are not too clear :smileygrin:


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

Reply
0 Kudos