2 Replies Latest reply on Mar 4, 2016 5:44 AM by Bill_W

    Another orphaned VMDK script thread

    Bill_W Lurker

      I am running the VMDK-orphaned-2.ps1 script to identify which data stores have orphans.  I am not sure if its environmental or the script itself but it is very slow.  We have about 170 data stores in two data centers in one vcenter.  I let it run for 15 hours and it made it thorough less than half of the data stores. 


      Any tips to speed the thing up.  I am trying to run it between backup windows to identify potential problems before we get the errors in the backups. 

        • 1. Re: Another orphaned VMDK script thread
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          Do you have a link to the script you are using ?

          Do you run it against all 170 datastores in one run ?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Another orphaned VMDK script thread
            Bill_W Lurker

            This is what I am running.  I am running it as is so it is going against the entire vcenter.  I got it from this thread orphaned vmdk files script


            $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 = "[" + $ds.Name + "]"

                $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 = [math]::Round($fileResult.FileSize/1GB,1)

                                $row.ModDate = $fileResult.Modification

                                $report += $row






            $report | Export-Csv "C:\orphans.csv" -NoTypeInformation -UseCulture