VMware Cloud Community
Bill_W1
Contributor
Contributor

Another orphaned VMDK script thread

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. 

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

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

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


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

Reply
0 Kudos
Bill_W1
Contributor
Contributor

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

Reply
0 Kudos