An interactive PowerShell tool to export and import virtual machines against a
VMware vCenter (including Distributed Switch environments) or a standalone
ESXi host. Built on VCF.PowerCLI.
Exporting a VM to OVF/OVA and importing it again is straightforward against a
single ESXi host, but importing into a vCenter that uses a vSphere Distributed
Switch (VDS) often fails — the network has to be mapped before the VM is
created. This tool solves that by mapping every OVF network to a target port
group via Get-OvfConfiguration prior to Import-VApp.
- Single menu-driven script for both export and import
- Automatic detection of the connection type (vCenter vs. standalone ESXi)
- Interactive network mapping to Distributed or Standard port groups
- OVF or OVA export (with a short explanation of the difference)
- Per-VM settings remembered in
config.jsonand offered for reuse next run - Secure credentials: prompt with optional encrypted storage (Windows DPAPI)
- Graceful guest shutdown before export, with power-state restore afterwards
- Module preflight: checks/installs
VCF.PowerCLI(CurrentUser scope; elevation only as a fallback) - Console and file logging
- Windows PowerShell 5.1 or PowerShell 7+
VCF.PowerCLI(installed automatically on first run if missing)- Network access to your vCenter/ESXi endpoint
.\VM-ImportExport.ps1Follow the menu:
| Key | Action |
|---|---|
1 |
Export VM(s) |
2 |
Import VM(s) |
C |
Switch connection |
Q |
Quit |
On first run you are prompted for server, username and password. Every prompted
value is stored in config.json next to the script and offered as a default the
next time (press Enter to keep it). When the same VM(s) are selected again,
the tool summarizes the saved settings and offers to reuse them.
- OVF — a folder of separate files (
.ovfdescriptor +.vmdkdisk(s) +.mfmanifest). Faster to write, easy to inspect/edit individual files. - OVA — a single packaged archive (
.ova), a tar bundle of the same OVF set. One portable file, easier to copy/share, but must be unpacked to edit.
The importer auto-detects both OVF folders and OVA files in the source path.
config.json(git-ignored) holds non-secret settings and per-VM profiles.cred_<server>_<user>.xml(git-ignored) holds optional DPAPI-encrypted credentials, decryptable only by the same user on the same machine. Passwords are never written toconfig.json.- Logs are written to
logs/(git-ignored).
- A VM must be powered off to be exported; the script handles this via a graceful guest shutdown (falling back to a hard power-off) and can restore the original power state afterwards.
- For vCenter targets the importer prefers a cluster (letting DRS place the VM); otherwise it targets an individual host.