VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get Datastore size and Host LUN ID

Hi,

Please help, how can I get Datastore Size and Host LUN ID from the below script

Get-View -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

    $ds.Host | ForEach-Object -Process {

        New-Object -TypeName PSObject -Propert ([ordered]@{

            Datastore = $ds.Name

            DatastoreSize = $ds.CapacityGB

            Host = (Get-View -Id $_.Key -Property Name).Name

            Mounted = if($_.MountInfo.Mounted){'Mounted'}else{'Unmounted'}

            'Datastore Connectivity' = if($_.MountInfo.Accessible){'Connected'}else{'Not Connected'}

            'Mount Point' = $_.MountInfo.Path

        })

    }

}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-View -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

    $ds.Host | ForEach-Object -Process {

        $esx = Get-View -Id $_.Key -Property Name

        New-Object -TypeName PSObject -Propert ([ordered]@{

            Datastore = $ds.Name

            DatastoreSize = [math]::Round($ds.Summary.Capacity/1GB)

            Host = $esx.Name

            LUN = &{

                if($ds.Info.Vmfs){

                    $dev = $ds.Info.Vmfs.Extent[0].DiskName

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

                    $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')

                }

                else{'na'}

            }

            Mounted = if($_.MountInfo.Mounted){'Mounted'}else{'Unmounted'}

            'Datastore Connectivity' = if($_.MountInfo.Accessible){'Connected'}else{'Not Connected'}

            'Mount Point' = $_.MountInfo.Path

        })

    }

}


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

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-View -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

    $ds.Host | ForEach-Object -Process {

        New-Object -TypeName PSObject -Propert ([ordered]@{

            Datastore = $ds.Name

            DatastoreSize = [math]::Round($ds.Summary.Capacity/1GB)

            Host = (Get-View -Id $_.Key -Property Name).Name

            LUN = $ds.Info.Vmfs.Extent.DiskName -join '|'

            Mounted = if($_.MountInfo.Mounted){'Mounted'}else{'Unmounted'}

            'Datastore Connectivity' = if($_.MountInfo.Accessible){'Connected'}else{'Not Connected'}

            'Mount Point' = $_.MountInfo.Path

        })

    }

}


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

My bad, if I am not clear earlier, I am seeing naa id but I am want to get LUN number of the Datastore.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean like in this question of yours that I answered?
Re: Get LUN ID of Datastore


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

yes LucD, I want the LUN number to added the script.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Really?

You can't copy/paste that snippet from that other answer?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried copying from that thread and I am getting this error

Get-View -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

    $ds.Host | ForEach-Object -Process {

        New-Object -TypeName PSObject -Propert ([ordered]@{

            Datastore = $ds.Name

            DatastoreSize = [math]::Round($ds.Summary.Capacity/1GB)

            Host = (Get-View -Id $_.Key -Property Name).Name

            NAA = $ds.Info.Vmfs.Extent.DiskName -join '|'

LUN = ($esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

$dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

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

$esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L'))

            Mounted = if($_.MountInfo.Mounted){'Mounted'}else{'Unmounted'}

            'Datastore Connectivity' = if($_.MountInfo.Accessible){'Connected'}else{'Not Connected'}

            'Mount Point' = $_.MountInfo.Path

        })

    }

} | ft -auto

Error

At line:8 char:71

+ ... UN = ($esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

+                                                                          ~

Missing closing ')' in expression.

At line:9 char:2

+  $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

+  ~~~~

Unexpected token '$dev' in expression or statement.

At line:8 char:71

+ ... UN = ($esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

+                                                                          ~

The hash literal was incomplete.

At line:9 char:1

+  $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

+ ~

Missing closing ')' in expression.

At line:2 char:40

+     $ds.Host | ForEach-Object -Process {

+                                        ~

Missing closing '}' in statement block or type definition.

At line:1 char:77

+ ...  -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

+                                                                         ~

Missing closing '}' in statement block or type definition.

At line:11 char:98

+ ... t.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L'))

+                                                                         ~

Unexpected token ')' in expression or statement.

At line:15 char:9

+         })

+         ~

Unexpected token '}' in expression or statement.

At line:15 char:10

+         })

+          ~

Unexpected token ')' in expression or statement.

At line:16 char:5

+     }

+     ~

Unexpected token '}' in expression or statement.

Not all parse errors were reported.  Correct the reported errors and try again.

    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : MissingEndParenthesisInExpression

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-View -ViewType Datastore -PipelineVariable ds | ForEach-Object -Process {

    $ds.Host | ForEach-Object -Process {

        $esx = Get-View -Id $_.Key -Property Name

        New-Object -TypeName PSObject -Propert ([ordered]@{

            Datastore = $ds.Name

            DatastoreSize = [math]::Round($ds.Summary.Capacity/1GB)

            Host = $esx.Name

            LUN = &{

                if($ds.Info.Vmfs){

                    $dev = $ds.Info.Vmfs.Extent[0].DiskName

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

                    $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')

                }

                else{'na'}

            }

            Mounted = if($_.MountInfo.Mounted){'Mounted'}else{'Unmounted'}

            'Datastore Connectivity' = if($_.MountInfo.Accessible){'Connected'}else{'Not Connected'}

            'Mount Point' = $_.MountInfo.Path

        })

    }

}


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD. that worked Smiley Happy

Reply
0 Kudos