VMware Cloud Community
Nataraki
Contributor
Contributor
Jump to solution

powershell script that can pull NFS datastore info mounted from VC host

Hello! I would like to ask assistance to create a powershell script that can pull the following multiple

NFS datastore1, datastore2, mounted to multiple ESXi  v5/v6 Host in a VCenter and the possibility to send schedule email report.

sample output should be like this.

Datastorename    RemotePath          RemoteHost     VMname UsedSpaceGB ProvisionedSpaceGB  ownerfolder

Datastore1          /vol/datastore1/a1  192.168.192.10   VM1         30                80                                OS1

Hope someone can assist me, thank you in advance Smiley Happy

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datastore -PipelineVariable ds | where{$_.Type -match "NFS"} | %{

    Get-VM -Datastore $_ |

    Select @{N='DatastoreName';E={$ds.Name}},

        @{N='RemotePath';E={$ds.RemotePath}},

        @{N='RemoteHost';E={$ds.RemoteHost}},

        @{N='VM';E={$_.Name}},

        @{N='UsedSpaceGB';E={

            $script:sp = $_.ExtensionData.Storage.PerDatastoreUsage | where{$_.Datastore -eq $ds.ExtensionData.MoRef}

            [math]::Round($script:sp.Committed/1GB,1)

        }},

        @{N='ProvisionedSpaceGB';E={

            [math]::Round(($script:sp.Committed + $script:sp.Uncommitted)/1GB,1)

        }},

        @{N='OwnerFolder';E={Get-Annotation -Entity $_ -Name ownerFolder | select -ExpandProperty Value}}

}

 


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this.

I have no idea what you mean by OwnerFolder.

Get-Datastore -PipelineVariable ds | where{$_.Type -match "NFS"} | %{

    Get-VM -Datastore $_ |

    Select @{N='DatastoreName';E={$ds.Name}},

        @{N='RemotePath';E={$ds.RemotePath}},

        @{N='RemoteHost';E={$ds.RemoteHost}},

        @{N='VM';E={$_.Name}},

        @{N='UsedSpaceGB';E={

            $script:sp = $_.ExtensionData.Storage.PerDatastoreUsage | where{$_.Datastore -eq $ds.ExtensionData.MoRef}

            [math]::Round($script:sp.Committed/1GB,1)

        }},

        @{N='ProvisionedSpaceGB';E={

            [math]::Round(($script:sp.Committed + $script:sp.Uncommitted)/1GB,1)

        }}

}


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

Reply
0 Kudos
Nataraki
Contributor
Contributor
Jump to solution

Hi Lucd,

Ownerfolder is from vm annotation, see pic attached

Thank you.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datastore -PipelineVariable ds | where{$_.Type -match "NFS"} | %{

    Get-VM -Datastore $_ |

    Select @{N='DatastoreName';E={$ds.Name}},

        @{N='RemotePath';E={$ds.RemotePath}},

        @{N='RemoteHost';E={$ds.RemoteHost}},

        @{N='VM';E={$_.Name}},

        @{N='UsedSpaceGB';E={

            $script:sp = $_.ExtensionData.Storage.PerDatastoreUsage | where{$_.Datastore -eq $ds.ExtensionData.MoRef}

            [math]::Round($script:sp.Committed/1GB,1)

        }},

        @{N='ProvisionedSpaceGB';E={

            [math]::Round(($script:sp.Committed + $script:sp.Uncommitted)/1GB,1)

        }},

        @{N='OwnerFolder';E={Get-Annotation -Entity $_ -Name ownerFolder | select -ExpandProperty Value}}

}

 


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

Nataraki
Contributor
Contributor
Jump to solution

{revised]

Hi Lucd,

Thank your time helping on this, can i request to revise the output, the owner folder/vm owner  should not come from annotation. It should be get in VM tab. find attache pic for reference- VMtab-customer.jpeg

Also if possible to add in the scipt the datastore configuration details ex. Indentification tab / status / device / capacity / free , ffind attached pic  - datastorepath configuration.jpeg

Thank you

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I have no clue where that Owner column is coming from, if not a Custom property.

Do you also have that view in the Web Client?


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

Reply
0 Kudos