Using PowerCLI to import and export VMs with VMware Cloud on AWS

2 minute read
Content level: Intermediate
2

Provides specific import and export command syntax for VMware Cloud on AWS

Task

A customer wants to be able to import OVFs and export VMs to OVF with VMware Cloud on AWS.

Assumptions

  1. This article assumes you have already installed VMware PowerCLI and have connected to your VMC on AWS vCenter with Connect-VIServer

  2. VMware retired ESXi host port 902 in vSphere 8. All current versions of VMC on AWS use vSphere 8. You must have access to ESXi host port 443 for these commands to succeed.

Import

# Disable warnings since we have to import directly to a host
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

# This is the name of the portgroup we want the VM to be connected to
$pg Get-VDPortgroup "nva-cgw-web"

# This is the local path to our OVF that we want imported
$ovfconfig = Get-OvfConfiguration .\Ubuntu_VM.ovf

Here we see the network mapping defined in the OVF

$ovfconfig.NetworkMapping

nva_cgw_web
-----------

Here we look at the available properties of the network mapping defined in the OVF. Since this VM was exported from the same vCenter that we're importing back into, the network name nva_cgw_web is the same

$ovfconfig.NetworkMapping.nva_cgw_web

Key                : NetworkMapping.nva-cgw-web
Value              :
DefaultValue       :
OvfTypeDescription : string
Description        : The nva-cgw-web network

Assign the portgroup to the network mapping.

$ovfconfig.NetworkMapping.nva_cgw_web.value = $pg

Execute the import. The IP address for Get-VMHost is any of the hosts in the VMC on AWS cluster. The datastore name for Get-Datastore will always be WorkloadDatastore unless you have secondary storage attached to your cluster. Location can be any valid VI Container, here we choose the name of the first cluster in our SDDC. Finally, we pass the OVF Configuration data that we built.

Import-VApp -source .\Ubuntu_VM.ovf -vmhost (Get-VMHost "172.16.0.70") -Datastore (Get-Datastore "WorkloadDatastore") -Location (Get-Cluster "Cluster-1") -OvfConfiguration $ovfconfig

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
Ubuntu_VM            PoweredOff 1        2.000

Export

Exporting is a simple command

Export-VApp -VM (Get-VM "Ubuntu_VM")

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          10/11/2023  6:51 PM          12147 Ubuntu_VM.ovf
-a---          10/11/2023  6:51 PM     1312683520 Ubuntu_VM_disk0.vmdk
-a---          10/11/2023  6:51 PM           8684 Ubuntu_VM_file0.nvram
-a---          10/11/2023  6:51 PM            279 Ubuntu_VM.mf
profile pictureAWS
EXPERT
published 6 months ago1232 views