{"id":1090,"date":"2018-02-04T17:53:08","date_gmt":"2018-02-04T22:53:08","guid":{"rendered":"https:\/\/ithinkvirtual.com\/?p=1090"},"modified":"2018-02-10T08:55:54","modified_gmt":"2018-02-10T13:55:54","slug":"deploy-a-virtual-appliance-using-powercli","status":"publish","type":"post","link":"https:\/\/ithinkvirtual.com\/2018\/02\/04\/deploy-a-virtual-appliance-using-powercli\/","title":{"rendered":"Deploy A Virtual Appliance Using PowerCLI"},"content":{"rendered":"

Hello all and thank you for visiting my blog!\u00a0 In today’s post, I am going to cover how to deploy a VMware virtual appliance (.ova) using PowerCLI.\u00a0 “Why?” you asked?\u00a0 Well, because scripting and automation via PowerCLI is fun and awesome!\u00a0 Sure, it’s simple enough to deploy an appliance natively within the vSphere Web Client by selecting the .ova that you’d like to import, press a few mouse clicks, enter some info, and off you go!\u00a0 But who wants to do stuff the easy way?\u00a0 It takes the fun away!<\/p>\r\n

In my opinion, scripting this out is just as easy since you can pre-populate your information into variables, and then run a simple “one-liner” command to kick off the deployment.\u00a0 Pretty neat right?\u00a0<\/p>\r\n

Now, I do understand that initially doing a deployment this way is a bit time-consuming.\u00a0 But once you have the method and process down, you can create a simple PowerShell script with all of your information embedded, then simply tweak\/adjust it as needed per appliance.\u00a0 The only time-consuming part is identifying the proper variables for each appliance.\u00a0 Please keep in mind that while most appliances have the same initial setup variables, some may have more and some may have less so it is always best to follow the initial steps I’ll cover below for each appliance to ensure you have all the correct information for your deployment and\/or script.<\/p>\r\n

Well, let’s get to it, shall we!<\/p>\r\n

In this example, I will be using the latest version of PowerCLI which, at the time of this writing, is 6.5.4.7155375, to deploy the VMware Support Assistant appliance for vSphere 6.5.<\/p>\r\n

\"\"<\/a><\/p>\r\n

To kick things off, we will be using two important variables, $ovfPath<\/strong><\/em>, and $ovfConfig<\/strong><\/em>.\u00a0 The latter will use the $ovfPath<\/strong><\/em> variable to discover the correct variable properties to build out our $ovfConfig<\/strong><\/em>.\u00a0 I’ll assume that you’re already connected to your vCenter server in the PowerCLI session but, if not, please go ahead and do so using the “Connect-VIServer<\/strong><\/em>” cmdlet.<\/p>\r\n

\"\"<\/a><\/p>\r\n

Let’s define our $ovfPath<\/strong><\/em> first:<\/p>\r\n

$ovfPath = \"<path_to_ova_file>\"<\/pre>\r\n

Next, let’s define $ovfConfig<\/strong><\/em><\/p>\r\n

$ovfConfig = Get-OvfConfiguration\u00a0-Ovf $ovfPath<\/pre>\r\n

Great!\u00a0 Now if we simply type $ovfConfig<\/strong><\/em>, it will check our $ovfPath<\/strong><\/em> for the file and list the setup properties.<\/p>\r\n

\"\"<\/a><\/p>\r\n

We can see that it has identified “Common<\/em><\/strong>“, “IpAssignment<\/strong><\/em>“, “NetworkMapping<\/strong><\/em>“, and “vami<\/strong><\/em>”\u00a0as the starting base properties.\u00a0 Next, we will have to drill down into each of these properties to determine the full property “Value<\/strong><\/em>” to define our variable with.<\/p>\r\n

So starting with “Common<\/strong><\/em>“, let’s drill down more by typing:<\/p>\r\n

$ovfConfig.Common<\/pre>\r\n

This now identifies the next “Common<\/strong><\/em>” property which is “varoot_password<\/strong><\/em>“.\u00a0 Let’s drill into that to see what it finds.<\/p>\r\n

$ovfConfig.Common.varoot_password<\/pre>\r\n

This gives us more information about the property and the key one here is “Value<\/strong><\/em>“.\u00a0<\/p>\r\n

\"\"<\/a><\/p>\r\n

This means that we have reached the last property entry needed to define our first config variable with.\u00a0 Great! With this information, our first defined configuration variable will look like this:<\/p>\r\n

$ovfConfig.Common.varoot_password.Value = \"<some_password>\"<\/pre>\r\n

Let’s now move to the next property, “IpAssignment<\/strong><\/em>“.\u00a0 Following the same logic as before and drilling into this property identifies “IpProtocol<\/strong><\/em>” which requires a “string<\/em>” value of “IPv4<\/strong><\/em> or IPv6<\/strong><\/em>“.\u00a0<\/p>\r\n

\"\"<\/a><\/p>\r\n

This means our next defined variable will look like this.<\/p>\r\n

$ovfConfig.IpAssignment.IpProtocol.Value = \"IPv4\"<\/pre>\r\n

Now for the next property, “NetworkMapping<\/strong><\/em>“.\u00a0 Drilling down into this property identifies “Network_1<\/strong><\/em>” which again will be a “string<\/em>” value for our variable.\u00a0 This string is the VM PortGroup that you want to attach to the appliance, whether it be on a virtual Standard Switch\u00a0(vSS) or Distributed Switch (vDS).<\/p>\r\n

\"\"<\/a><\/p>\r\n

This defined variable will look like this.<\/p>\r\n

$ovfConfig.NetworkMapping.Network_1.Value = \"<some_vm_portgroup>\"<\/pre>\r\n

Getting the gist of this yet?\u00a0 Let’s move onto the final property, “vami<\/strong><\/em>“.\u00a0 Again, following the same logic we’ve been doing and drilling into the “vami<\/em>” property, we can see that it has identified the “appliance<\/em>” as “VMware_vCenter_Support_Assistant_Appliance<\/strong><\/em>“.\u00a0 Drilling down further, there are multiple properties discovered in this one and they are “gateway<\/strong><\/em>“, “domain<\/strong><\/em>“, “searchpath<\/strong><\/em>“, “DNS<\/strong><\/em>“, “ip0<\/strong><\/em>“, and “netmask0<\/strong><\/em>“.<\/p>\r\n

\"\"<\/a><\/p>\r\n

Whoa! Quite a few huh?\u00a0 Yet again, drilling into each of these lets us know that “string<\/em>” values are required for each property.<\/p>\r\n

\"\"<\/a><\/p>\r\n

These config variables will be defined like this.<\/p>\r\n

$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.gateway.Value = \"<gateway_ip>\"\r\n$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.domain.Value = \"<domain_name>\"\r\n$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.searchpath.Value = \"<dns_searchpath>\"\r\n$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.DNS.Value = \"<dns_ip(s)>\"\r\n$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.ip0.Value = \"<appliance_ip>\"\r\n$ovfConfig.vami.VMware_vCenter_Support_Assistant_Appliance.netmask0.Value = \"<netmask_ip>\"<\/pre>\r\n

From what we’ve obtained so far, all of our defined variables look like this.<\/p>\r\n

\"\"<\/a><\/p>\r\n

Ready to deploy the appliance?\u00a0 Not quite yet!\u00a0 There are some additional variables we can create\/define to make the syntax of our command shorter, neater, and nicer.\u00a0 First, let’s see what the cmdlet requires.\u00a0 The cmdlet used to deploy an appliance is “Import-vApp<\/a>“.\u00a0 Clinking that link and reviewing the table show us what is required or not.<\/p>\r\n

\"\"<\/a><\/p>\r\n

From this table, I am going to define some more variables for the following parameters.<\/p>\r\n