If you use strong and complex passwords that contain special characters (which you should), it can some times be challenging from an automation perspective on how to properly escape these characters, which can also depend on the scripting or programming language that you are using.
Today I learned about a nice little enhancement in OVFTool 4.4 or later, which makes it easy to handle complex passwords containing special characters by supporting URL encoding for these characters. This is also great for those writing automation scripts and not having to input the password interactively but can now be added to OVFTool command-line string.
As an example, lets take the following password: #/MySuperSecretPassword\# which is valid for ESXi, but is problematic for a few reason. The use of the forward slash (/) character is an issue as that that is a delimiter for the OVFTool connection string and both the back slash (\) and number sign (#) also special characters that will cause parsing errors.
Using this URL encoding reference, we simply encode these special characters into the following:
- # 👉 %23
- / 👉 %2F
- \ 👉 %5C
and we now end up with the following password string: %23%2FMySuperSecretPassword%5C%23
Once we properly encode these special characters, we can now pass our password directly or in-directly through the use of a variable on the command-line to OVFTool:
ovftool "vi://root:#/MySuperSecretPassword\#@192.168.30.120"
Luke Huckaba says
You can also do this in powershell:
$password = "#/MySuperSecretPassword\#"
Add-Type -AssemblyName System.Web
$encodedPassword = [System.Web.HttpUtility]::UrlEncode($password)
Now $encodedPassword is %23%2fMySuperSecretPassword%5c%23