For this purposes there are numerous scripts around that will compare the files of registered VMs with the actual list of vmdk files found in a Datastore
Examples:
- https://communities.vmware.com/message/1527123
- http://virtuallyjason.blogspot.dk/2013/08/orphaned-vmdk-files.html
- http://www.lucd.info/2011/04/25/orphaned-files-and-folders-spring-cleaning/
There is however one problem no one seem to be able to address at all accross all these scripts. When you search "very" large datastores and the esxcli / powercli have been running for 15 minutes the script get an exception. (Our VDI linkedclone datastore is very large)
Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "
An error o ccurred while communicating with the remote host
." At xxxxx + $searchResult = $dsBrowser.SearchDatastoreSubFolders <<<< ($rootPath, $se archSpec) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException".
I noticed the exception message was about the remote host so I figured it must be vCenter / ESXi related.
Based on above finding I found this vmware KB article that describe how to increase the timeout for tasks to vCenter and ESXCLI to much more than the default 15 minutes. I implemented the KB article on my vCenter server and on all the ESXi hosts in the cluster. This did the trick for me and I can now complete the datastore search. More specific I'm now able to complete this line of code from the scripts without the exception:
$xxx.SearchDatastoreSubFolders($rootPath, $searchSpec)
chmod u+w /etc/vmware/vpxa/vpxa.cfg
I hope this makes sense for everyone.Please comment if you have any questions or feedback.