Automation

 View Only
  • 1.  Get-Datastore

    Posted Aug 21, 2018 05:20 AM

    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?



  • 2.  RE: Get-Datastore

    Posted Aug 21, 2018 05:32 AM

    You mean like this?

    Get-DatastoreCluster -PipelineVariable dsc |

    Get-Datastore |

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



  • 3.  RE: Get-Datastore

    Posted Aug 21, 2018 05:49 AM

    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



  • 4.  RE: Get-Datastore

    Posted Aug 21, 2018 05:56 AM

    I suspect you might be using an older PowerShell version.

    Can you check what $PSVersionTable shows?



  • 5.  RE: Get-Datastore

    Posted Aug 21, 2018 06:04 AM

    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



  • 6.  RE: Get-Datastore

    Posted Aug 21, 2018 06:11 AM

    Try like this

    Get-DatastoreCluster |

    ForEach-Object -Process {

        $dsc = $_

        Get-Datastore -RelatedObject $dsc |

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

    }



  • 7.  RE: Get-Datastore

    Posted Aug 21, 2018 06:25 AM

    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:



  • 8.  RE: Get-Datastore

    Posted Aug 21, 2018 06:35 AM

    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



  • 9.  RE: Get-Datastore

    Posted Aug 21, 2018 06:54 AM

    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.



  • 10.  RE: Get-Datastore
    Best Answer

    Posted Aug 21, 2018 07:00 AM

    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



  • 11.  RE: Get-Datastore

    Posted Aug 21, 2018 09:07 AM

    mate, this works great!

    Thank you for your help