I'm looking to back up several of my virtual machines (VMs) using PowerShell, and I normally use the Export-VM command. However, I have some VMs that have very large VHDX files that I don't need to back up. Unfortunately, I can't find an option in Export-VM to exclude these specific files, and I want to avoid wasting resources by exporting the whole VM just to delete the VHDX afterwards. Is there a set of PowerShell commands that can help me export a VM while skipping specific VHDX files? I want to ensure I don't miss any important files in the process.
4 Answers
Consider using a dedicated backup utility; it might offer more flexible options for what you want to do.
You can't actually exclude VHDX files when using Export-VM, but one workaround is to detach the large VHDX before you export the VM and then reattach it afterward.
Have you checked if your backup software already supports excluding specific drives? Many tools let you skip certain drives during backups or even when restoring. They usually work quietly in the background too, so you might want to leverage that instead!
Another option is to manually copy the VM files and then delete the ones you don't want. Just so you know, Export-VM is quite similar to using xcopy but with some added functionalities.
Detaching the VHDX isn't acceptable for my situation. When you mentioned "export-vm is pretty much just xcopy with extra steps," which files are you talking about, and what are those steps?

I understand that detaching isn't an option for me. That's why I'm looking for other methods with PowerShell commands that could achieve a similar result.