VMware Cloud Community
afhamsani
Enthusiast
Enthusiast
Jump to solution

Get-Datastore

Hi,

May i know why datastore in the cluster datastore would not be listed from the cmdlet output?

How to combine these 2 cmdlet (get-datastore and get-datastorecluster) within a script to list all datastore?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Correct, it only lists datastores that belong to a datastorecluster.

If you want to see all datastores, you can do

Get-Datastore |

Select Name,@{N='DSC';E={

    if($_.ParentFolderId -match 'StoragePod'){

        Get-View -Id $_.ParentFolderId | select -ExpandProperty Name

    }

}} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You mean like this?

Get-DatastoreCluster -PipelineVariable dsc |

Get-Datastore |

Select Name,@{N='DSC';E={$dsc.Name}}


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

oh, that is how we could combine it both. my bad :smileysilly:

Thanks!

-PipelineVariable parameter seems cannot be found on my powercli, maybe outdated version that i have yeah?

I am using ise to construct more than one liner script.

Get-DatastoreCluster : A parameter cannot be found that matches parameter name 'PipelineVariable'.

At line:2 char:22

+ Get-DatastoreCluster -PipelineVariable dsc |

+                      ~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-DatastoreCluster], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastoreCluster

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you might be using an older PowerShell version.

Can you check what $PSVersionTable shows?


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

yup,i agree with you. for this server where i currently work on, it is older version than other one i usually work on.

Get-DatastoreCluster : A parameter cannot be found that matches parameter name 'PipelineVariable'.

At line:2 char:22

+ Get-DatastoreCluster -PipelineVariable dsc |

+                      ~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-DatastoreCluster], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastoreCluster

i am going to update this now than later

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-DatastoreCluster |

ForEach-Object -Process {

    $dsc = $_

    Get-Datastore -RelatedObject $dsc |

    Select Name,@{N='DSC';E={$dsc.Name}}

}


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

Yes, this works!

Only thing it thrown with this query at the end of line after showing all output, do you know why?

Name : KMBA_DS008_T1S

DSC  : KMBA_CDS001

cmdlet Export-Csv at command pipeline position 1

Supply values for the following parameters:

InputObject:

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-DatastoreCluster |

ForEach-Object -Process {

    $dsc = $_

    Get-Datastore -RelatedObject $dsc |

    Select Name,@{N='DSC';E={$dsc.Name}}

} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

LucD​,

ok,thats it! i missed this ' | ' before making output sentence

But, what i found was the script didnt list other datastores that is not part of the datastore cluster.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Correct, it only lists datastores that belong to a datastorecluster.

If you want to see all datastores, you can do

Get-Datastore |

Select Name,@{N='DSC';E={

    if($_.ParentFolderId -match 'StoragePod'){

        Get-View -Id $_.ParentFolderId | select -ExpandProperty Name

    }

}} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

mate, this works great!

Thank you for your help

Reply
0 Kudos