User Guide for the Import OVA files
Prerequisites
The following files and folders should have been sent to you along with this guide:
| Item | Description |
|---|---|
Import-VMs-from-OVA.ps1 | The script itself |
ovftool folder | Auxiliary tool required by the script |
.ova files | Virtual machine files to be imported, such as Mux.ova and Access.ova |
| This guide | This file |
You also need PowerShell installed on your system. On Windows, PowerShell is available by default.
Step 1: Preparing Files on the System
- Copy the
ovftoolfolder to a path on your system; for example:
C:\Tools\ovftool
- Place the
.ovafiles in a specific folder; for example:
E:\Exports
- Save the
Import-VMs-from-OVA.ps1file on the system.
Adding ovftool to PATH
-
Press the Windows key, search for Environment Variables, and open it.
-
Click Environment Variables.
-
Under System variables, select the
Pathvariable and click Edit. -
Add the path to the folder containing
ovftool.exe; for example:
C:\Tools\ovftool
- Close all windows with OK, and open a new PowerShell window.
To verify this step, run the following command in PowerShell:
Get-Command ovftool
If the configuration is correct, the path to ovftool.exe should be displayed.
Note: If the above command returns an error, the step to add
ovftoolto PATH was not completed correctly.
Step 2: Editing the Script
Open the Import-VMs-from-OVA.ps1 file with Notepad or PowerShell ISE.
At the beginning of the file, there is a section named CONFIGURATION. Change only the following values according to your environment:
$EsxiHost = "172.16.41.3" # Destination ESXi server IP
$Datastore = "DataStore" # Datastore name on the destination server (without [] and case-sensitive)
$SourceDir = "E:\Exports" # Folder where the .ova files are located
$VMNames = @("Mux", "Access") # VM names; must exactly match the .ova file names (without extension)
$DiskMode = "thin" # Disk mode
Important Notes When Editing
-
Replace the
$EsxiHostvalue with the IP of your ESXi server. -
The
$Datastorevalue must be exactly the same as the datastore name on the destination server, and it is case-sensitive. -
If your
.ovafile names differ fromMux.ovaandAccess.ova, change the$VMNameslist to match the file names. For example, if your files areWeb.ovaandDB.ova:$VMNames = @("Web", "DB") -
In
$VMNames, the file names must be written without the.ovaextension.
After applying the changes, save the file.
Step 3: Running the Script
-
Open PowerShell with the Run as Administrator option.
-
Navigate to the folder where the script is located:
cd C:\path\to\script\folder
- If running the script results in an Execution Policy error, run the following command once:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
- Run the script:
.\Import-VMs-from-OVA.ps1
Step 4: Entering Credentials at Runtime
When run, the script asks you for the following information:
| Prompt | Description |
|---|---|
Enter ESXi username | ESXi server username; usually root |
Enter ESXi password | Password for that user; it is not displayed while typing |
After receiving the login information, the script automatically imports all virtual machines defined in $VMNames, in order.
The progress of the operation is also displayed in the same PowerShell window.
Step 5: Checking the Result
At the end of the run, the script displays a summary of the operation result:
-
If a SUCCESS message appears in green, that virtual machine was imported successfully.
-
If a FAILED message appears along with an error code, that virtual machine failed to import.
At the end of the output, a list of successful and failed virtual machines is also displayed.
Step 6: After Import — Important
Virtual machines are imported in a Powered OFF state, and the script intentionally does not power them on.
Before powering on each virtual machine, perform the following steps:
-
Log in to the ESXi server management interface, such as vSphere Client or Host Client.
-
Right-click the imported virtual machine and select Edit Settings.
-
Check the Network Adapter section:
- The virtual machine may be connected to a portgroup that does not exist.
- The network adapter may be completely Disconnected.
-
Correct the NIC settings and click OK.
-
After ensuring the settings are correct, power on the virtual machine.
Troubleshooting Common Errors
| Error | Cause and Solution |
|---|---|
ERROR: ovftool not found in PATH | The step to add ovftool to PATH was not completed, or PowerShell was not reopened after changing PATH. |
ERROR: You still need to set EsxiHost... | The EsxiHost or $Datastore values in the CONFIGURATION section have not been edited. |
ERROR: Cannot find ... \Mux.ova | The SourceDir path is wrong, or the file name does not match the VMNames value. |
FAILED: ... (exit code ...) | Usually occurs due to an incorrect IP, username, password, or datastore name. Check the CONFIGURATION section values and credentials. |
| Execution Policy error when running | Run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass, then run the script again. |
Summary
Before running the script, check the following:
ovftoolhas been added to PATH.- The
$SourceDirpath is correct. - The
$EsxiHostvalue is correct. - The
$Datastorename exactly matches the ESXi datastore. - The
$VMNamesvalues match the.ovafile names. - The ESXi login credentials are correct.
- After import, the Network Adapter settings of the virtual machines are checked.