Quantcast
Channel: VMware Communities : All Content - VMware vCenter™
Viewing all articles
Browse latest Browse all 24426

Issue calling SearchDatastoreSubFolders function on one particular datastore

$
0
0

Hi all,

 

I am looking for some help in regards to this peculiar issue.  The below script works 100% fine for all of my vcenter's datastores with the exception of one.  It produces the below error stating there are communication issues with the datastore.  The datastore in question is online, accessible and otherwise running fine.

 

Has anyone run into a similar issue?  The script is fine as it works with all other datastores, perhaps some reconfiguration of the problematic datastore is the solution?

 

Any help is appreciated.  Thanks in advance.

 

Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "An error o

ccurred while communicating with the remote host."

At C:\Scripts\Running\engineeringoprhaned.ps1:18 char:58

+         $searchResult = $dsBrowser.SearchDatastoreSubFolders <<<< ($rootPath,

$searchSpec)

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

 

$report = @()
$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}
$arrDS = Get-Datastore | Sort-Object -property Name

foreach ($strDatastore in $arrDS) {
     Write-Host "Checking" $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 ($fileResult.Path.contains("ctk.vmdk"))) #Remove Change Tracking Files
                 {
                     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
                     }
                 }
             }
         }
     }
}


Viewing all articles
Browse latest Browse all 24426

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>