sp93
Contributor
Contributor

Way to report on Orphaned .VMDK files

I have looked in multiple locations, however aren't finding what I need. Many scripts will only report on clusters, or will also register the found VMDK files, which is what I don't want.

I would love (as I'm sure others would) to have a report in a .csv format that will scan my ESX 3.5 update 4 servers in my VC 2.5 update 4, and report any .VMDK files that aren't registered in VC.

We have iSCSI, storage as well as local storage being used on each server.

I have searched high and low for something, yet I can't seem to find anything that works.

thanks in advance.

0 Kudos
30 Replies
seaJhawk
Contributor
Contributor

I'm running the script against some of my ESX servers. It processed fine for a number of servers, but it's hanging (not crashing, not failing - just continuing to process w/o any CPU activity) at the following line for a long time - probably 10 minutes at least.

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

The ESX servers are all on the same network and I'm running the script on the VirtualCenter Server.

Is it normal for "SearchDatastoreSubFolders" method to take such a long time? I did browse the datastores through Infrastructure Client and browsing some of the datastores on the same ESX servers took a VERY long time too. Any idea what could be causing it to be so slow?

Thanks,

Chris

0 Kudos
seaJhawk
Contributor
Contributor

Never mind.

After the datastore browser finished searching for files I found that there were a couple thousand old log files in several of the folders in the datastore. I'm guessing this is why it's slow, but it would be nice if I could speed up the search.

Great Script!

Thanks,

Chris

0 Kudos
Adidas6
Contributor
Contributor

I just wanted to chime in as well and say that this is an amazingly helpful script! It has helped me clear out much space on my datastores. I tore it down and wrote about a half dozen scripts based on it to report on several different types of file-related issues. (Log bloat, random .iso's, etc)

LucD thanks for pointing out those fixes! I recently upgraded to vSphere and was worried about stuff like that breaking.

0 Kudos
sbrad001
Contributor
Contributor

I've tried to run this with teh updated code for vSphere, but I keep getting this error:

Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "Datastore '[SAN001 (LUN 804)]' is not accessible."

At :line:38 char:55

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

This isnt the first lun it hits. I've tried excluding that LUN thinking there was an issue.. but it will just hang up on the next LUN. I checked that I can browse them just fine.

0 Kudos
kkkoh
Contributor
Contributor

I'm also try to get more info about vmware.vim.viconvert but no luck. Any idea how to convert this script in vb.net using vmware.vim dll as I can't find any resource available? It seems vimapi_40 class from vmware.vim is different from vim25api class for vSphere 4.

0 Kudos
marrag
Contributor
Contributor

Is there a solution now for the "Not initialized: boolean fileOwner" Problem ?

I have excact the same Problem a s mentioned above, even when i set the $searchSpec.Details.FileOwner =$true explicit.

I'm using PowerCLI 4.0 build 162509 on a VSphere environment.

Greetings

0 Kudos
LucD
Leadership
Leadership

Yes, see Yasen's reply in


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

0 Kudos
PauloFreitas
Contributor
Contributor

Thanks a lot Lucd for this great and very useful script, and Yasen for the work around for vSphere 4 fileOwner bug.

I'm new to powercli and vsphere scripting and I have one question, How can I suppress the ctk.vmdk files from the results, since they aren't actually orphaned vmdks but "change tracking" vmdk files?

Or even better, is it possible to just show the ctk.vmdk file if it is associated with a vmdk file which in turn is orphaned? In the mean time I will keep looking into this and will post any findings I might have...

Thanks in advance,

Kind regards from Brazil,

Paulo

0 Kudos
LucD
Leadership
Leadership

You could try changing the test

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

into

if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path) -and $fileResult.Path -notmatch "ctk.vmdk ")){

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
PauloFreitas
Contributor
Contributor

It worked!

Just had to change the parenthesis to

if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path)) -and $fileResult.Path -notmatch "ctk.vmdk"){

Thanks a lot!

PS. An observation: Yasen workaround also suppressed flat.vmdk from the results (which appeared when the "details" property were left out) maybe there is a way of using "VMware.Vim.VIConvert" as a way of tying ctk with its respective vmdk and that way if there is an orphaned ctk file it would show up on the results. Not that it matters since CTK files ain't that big, but I thought it was worth mentioning.

0 Kudos
Sureshadmin
Contributor
Contributor

Hi Luc,

In my environment there is a known problem that a couple of datastore had VMFS crash and none of the esx box could read the contents of datastore. I'm running this script Get-orphaned-vmdk and when this script tries to retrive the contents of the corrupted datastore in the line $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec) the script breaks and halts. Could you please help to skip the datastore where it can't get the contents and continue with remaining datastores?

0 Kudos