Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 176483

orphaned vmdk files script

$
0
0

I found the below useful script for finding orphaned vmdk files as seen below:

 

  1. Purpose : List all orphaned vmdk on all datastores in all VC's

  2. Version: 1.1

  3. Author  : HJA van Bokhoven

  4. Modifications: LucD

 

$report = @()

$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}

$arrDS = Get-Datastore | Sort-Object -property Name

foreach ($strDatastore in $arrDS) {

          Write-Host $strDatastore.Name

          $ds = Get-Datastore -Name $strDatastore.Name | % {Get-View $_.Id}

          $fileQueryFlags = New-Object VMware.Vim.FileQueryFlags

          $fileQueryFlags.FileSize = $true

          $fileQueryFlags.FileType = $true

          $fileQueryFlags.Modification = $true

          $searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec

          $searchSpec.details = $fileQueryFlags

          $searchSpec.matchPattern = "*.vmdk"

          $searchSpec.sortFoldersFirst = $true

          $dsBrowser = Get-View $ds.browser

          $rootPath = ""

          $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)

 

          foreach ($folder in $searchResult)

          {

               foreach ($fileResult in $folder.File)

               {

                    if ($fileResult.Path)

                    {

                         if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path))){

                              $row = "" | Select DS, Path, File, Size, ModDate

                              $row.DS = $strDatastore.Name

                              $row.Path = $folder.FolderPath

                              $row.File = $fileResult.Path

                              $row.Size = $fileResult.FileSize

                              $row.ModDate = $fileResult.Modification

                              $report += $row

                         }

                    }

               }

          }

     }

 

 

When I run this script, it lists my datastores, but then after each datastore it brings up the following error message:

 

Exception calling "SeachDatastoresubfolders" with "2" argument (s): Invalid datastore path..........

 

Is there any reason why this script would bring this error message, I am using the lastest version of powercli client, or would it mean I have no orphaned vmdk files.  Any advise.


Viewing all articles
Browse latest Browse all 176483

Trending Articles