VMware Cloud Community
internetrush
Contributor
Contributor

Deleting VSWP files from Local Datastore

hello all,

We have a lot of datatstores that have stale vswp files, as part of our weekly tasks, we would like to write some powershell script to go through and clean them up.

Basically do the following;

Scan through all datastores, find vswp files that are older than a month, attempt to delete them.

Was looking at this: http://www.lucd.info/2011/04/25/orphaned-files-and-folders-spring-cleaning/ to see if we could use the same base code but im not sure where these methods are documented and how to write the search spec etc...

Anyone have any idea how to write this code? Can i just get the datastore like a drive mount it and attempt to delete files greater than a month old with the file extension for a virtual swap file?

Thanks!

Reply
0 Kudos
3 Replies
weinstein5
Immortal
Immortal

Are you sure they are not in use? When a VM is powered off the VSWP is automatically deleted -

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
Reply
0 Kudos
internetrush
Contributor
Contributor


No, they are not in use. Files that are in use do not allow deletion; however, we run into the situation where files are more than a few months old left over on the server and the vm is on an other host entirely with a seperate vswp file.

Reply
0 Kudos
internetrush
Contributor
Contributor

no one has any hints or can tell me how the above script was written?

Reply
0 Kudos