VM swapfiles: Leftover swapfiles

Every time a VM is started a swapfile is created on the datastore where the VM resides.

The format for these files are .vswp

I was working my way through a customers datastores, trying to find some orphaned VMs or files that could be deleted and I noticed that many of the VM folder had the .vswp files and then some extra ones.

The extra vswp files had a different ending, and that was vswp.xxxxx, where the x’s represent a number.

These files are created when your ESXi hosts crash and when the VM was restarted, the file was still there so it’s renamed and a new .vswp file is created.

For an active VMware environment, you could potentially see a lot of these if you had some ESXi crashing on you in the past. For that environment (around 60 VMs)  I found 34 GB of “dead” .vswp files. That’s a lot when your Datastores are at full capacity.

But you really can’t manually go searching for these unless you like repetitive and brain-damaging work.

This really isn’t a big piece of code and really doesn’t deserve a script by itself 🙂

dir vmstores: -Recurse -Include *.vswp.* | Select Name,Folderpath

This will give you a output of:

Note: This will take a lot of time to run on bigger environments. I tried this in a big production environment (40+ Datastores) and it took 5 hours to run. But it found 24GB of emtpy .vswp files.

I hope this helps to find some space on your expensive SAN 🙂

Edit: Raphael Shitz at http://www.hypervisor.fr has a great script for searching for orphaned files on Datastores and he added a search for “*.vswp.*”.  And its a lot faster, only few minutes rather than hours. His site is in french so here is a link to his post through Google translate. And if you can read french, Allez.

11 thoughts on “VM swapfiles: Leftover swapfiles”

  1. PowerCLI one liner:

    get-datastore | ForEach-Object {Get-ChildItem “vmstore:\*\$($_.name)” -Recurse -Filter “vmx-*-?.vswp” | where {$_.name -notlike “vmx-*-1.vswp”} | select name,FolderPath} | ogv

    Output is name and location. Really quick to execute :).

  2. Any ideas on error?
    Get-ChildItem : Cannot call method. The provider does not support the use of
    At line:1 char:33
    + get-datastore | ForEach-Object {Get-ChildItem “vmstore:\*\$($_.name)”
    -Recurse …


    1. Nope sorry, I just ran it on one of my labs it still found the files. But if this relates to xaviers one liner I tried that as well. Running PowerCLI 6.3 ATM if that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *