## PowerCLI: Import-vApp OVA: Hostname cannot be parsed.

The other day I was rebuilding my lab using William Lam’s vGhetto vSphere Automated Lab Deployment script for vSphere 6.5. In the past I have run the 6.0 script successfully. As part of the script, there is an OVA of a host profile that William has made for the deployment, this is used for the configuration of the host.

This particular time I came across an error right after starting the process and immediately after connecting to the nesting host.  It was a bit of a strange error, pointing to the Import-vApp cmdlet but also saying, “Invalid URI: The hostname could not be parsed,” which sounded as though to be a DNS issue, I spent a little bit of time going through my DNS settings, making sure that the computer from which I was running the script was able to resolve the hostname. I moved off my MacBook using PowerCLI Core and tested from my Windows machine using PowerCLI 10.0, and received the same error.

I did some quick research and found nothing related to the specific error message and started to look at it piece by piece. I decided to pull apart the OVA file and try and run just the OVF – SUCCESS! There appears to be an issue with the OVA and the Import-vApp cmdlet in both PowerCLI Core and PowerCLI 10.0. I am yet to test the OVA in vSphere via the WebClient, but I suspect it may work as it should.

To pull apart the OVA, I recommend using 7ZIP and opening the .ova file and copy/paste the content.

5. Change your ESXI $NestedESXiApplianceOVA= to the .ovf file 6. rerun script. ## PowerCLI migrate vSwitch port groups to vDS in a different vCenter Over the 6 months I have been working hard on designing and implementing our latest infrastructure refresh and migration to another datacenter. This was a big task, especially when we had to migrate customer servers with minimal downtime. However, there were many more challenges we faced, however with the right planning in the design, these were fairly well handled. One of the challenges was that we were using Standard vSwitches in the old 5.5/5.1 environment due to some 3rd party applications back when the environment was 4.1 which caused issues when using a vDS. As we were building a new vCenter we decided the best method was to automate adding all the VM port groups along with their VLANs and LAG into the DvSwitch. One thing I’ve learnt from Alan Renouf is “The best script you will ever write is one that you stole from somebody’s website” which doesn’t mean steal it and claim it as your own, but if someone has a script that does exactly what you need, then use it, just make sure you give credit where credit is due. It just so happened by luck that right around the time I was starting to think about the process, I saw a twitter post from Ben Liebowitz “PowerCLI Script to create a new vDS Portgroups” – Beauty, this was exactly what I was after (albeit some small changes to suit). The next step was to get a script to match to do the initial export to CSV, after a quick google I came across a Luc Dekens script that he had written for someones request on the VMware Community Forums. It was pretty straight forward and only require some lines removed so that the CSV only had the columns required for the import. So once I had the scripts, it was down to testing the process on how to use them prior to prod. 1. Edit the Export vSwitch Configuration script from Luc Dekens 2. Run the script 3. Open the CSV (Make sure the columns names line up with the import script) **As we are exporting from a vSwitch and importing to vDS, we will need to manually add a new column to the exported CSV called numports and place the correct number of ports in each row (by default 8) . **Also remove any multiples of portgroups (e.g. if you have multiple hosts with the same Portgroups as these will be also in the csv) 4. Edit the Import script from Ben Liebowitz – Change the vDS name and LAG name to match your environment. – Update to the CSV path 5. Run the import script. 6. Confirm the ports have imported by looking at the vDS. The process is simple, so let’s break this down into some of the areas you can edit . In the export script, all you need to edit is the lines that control what information is exported to the CSV. Just remove the lines you do not require. for example I do not need the IP address, so I would remove the below line. @{N="IP";E={if($vNicTab.ContainsKey($pg.Name)){$vNicTab[$pg.Name].Spec.Ip.IpAddress}}} The csv will export to the directory you have set in PowerCLI when running the script. Below is what the csv will turn out like, however note that I have also added the numports in as well. ESX,pgName,vlanID,numports HyperVisor-Hostname,PortGroup_1,3005,8 HyperVisor-Hostname,Portgroup_2,3005,8 HyperVisor-Hostname,Portgroup_13,3007,8 HyperVisor-Hostname,Portgroup_34,3007,8 etc. Now for the Import. In the import script, make sure that you change the name of the vDS, ActiveUplink and the location of the CSV – So he following lines. # Set the VDS Name to variable$vds = "dvSwitch"
# Import the CSV of VLAN IDs, Portgroups, and # of ports
$vdsPortgroup = Import-Csv \path\to\New_Portgroups.csv get-vdswitch$vdsname | Get-VDPortgroup $portgroup.pgName | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -UnusedUplinkPort dvUplink1, dvUplink2, dvUplink3, dvUplink4 get-vdswitch$vdsname | Get-VDPortgroup \$portgroup.pgName | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort LAG