3 Replies Latest reply on Oct 7, 2019 4:33 AM by MRoushdy

    Listing content of datastores

    MRoushdy Enthusiast
    vExpert

      Hello,

       

      I have unregistered VMs in many datastores, I need to list them please.

        • 1. Re: Listing content of datastores
          MRoushdy Enthusiast
          vExpert

          I have more than 30 datastore that I must list their content, the following script didn't do it for me, and I need to list the datastore name, as well as the childitem type "datastrefolder" if possible please:

           

           

          $ds = Get-Datastore -Name MyDS

           

           

          New-PSDrive -Name TgtDS -Location $ds -PSProvider VimDatastore -Root '\' | Out-Null

           

           

          Get-ChildItem -Path TgtDS: -Recurse

           

           

          Remove-PSDrive -Name TgtDS

          • 2. Re: Listing content of datastores
            LucD Guru
            vExpertUser ModeratorsCommunity Warriors

            You could do something like this

             

            Get-Datastore -Name MyDS |

            ForEach-Object -Process {

                New-PSDrive -Name TgtDS -Location $_ -PSProvider VimDatastore -Root '\' | Out-Null

                Get-ChildItem -Path TgtDS: -Recurse | where{$_.PSIsContainer} | Select Datastore,DatastoreFullPath

                Remove-PSDrive -Name TgtDS

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

            • 3. Re: Listing content of datastores
              MRoushdy Enthusiast
              vExpert

              Thank you,