VMWare OVF Tool, Script in Powercli with ovtool.exe command in a windows Server

Hello all,

I’modify a script for doing some OVA image of a vApp.
The script is this :

# Adding the PowerCLI Modules
Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Clear the Screen and Make a Menu
write-host ""
write-host " PLEASE ENTER IN THE ZETTAGRID ZONE..." -ForegroundColor Green
write-host ""
write-host " 1. PERTH ZONE" 
write-host " 2. SYDNEY ZONE" 
write-host " 3. MELBOURNE ZONE" 
write-host ""
$answer = read-host "Please Make a Selection"
# Set the Zone from the Menu Option Selected otherwise Exit - No Fancy While Loop
if ($answer -eq 1)
elseif ($answer -eq 2)
elseif ($answer -eq 3)
write-host "You choose....poorly"
# Get the arguments needed for the OVFTOol to Connect and Download the vApp
write-host ""
$username=read-host "Enter in your vCloud Username"
$password=read-host "Enter in your vCloud Password" -AsSecureString
$vCD_ORG=read-host "Enter in your vCloud Organisation"
$vDC=read-host "Enter in your vCloud Virtual Datacenter"
$vApp=read-host "Enter in your vApp"
$catalog=read-host "Enter in your vCD Catalog"
Write-Host -NoNewline -ForegroundColor Red "Enter In the Full OVA Path"
$OVA=read-host " :"
write-host ""

#Convert Secure Password
$password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
# Build the vCloud Connection String

#Build the vCloud Connection String to Hide Password
write-host "vCloud Connection String" $vCloud2 -ForegroundColor Yellow
# Set the OVFTool EXE and execute it with some arguments 
$app = '.\ovftool.exe'
$arg1 = "$OVA"
$arg2 = "$vCloud"
& $app $arg1 $arg2
write-host ""
read-host "Hit Enter to Exit"

My problem is when i tape the command line directly in powershell (PowerCLI):


Of course all the variable is set before.
I have the error :
“Unexpected token ‘&’ in expression or statement. The ampersand (&) character is not allowed…”

Have you an idea ?

Thx for help.

You can use Start-Process for this.

Start-Process $app -ArgumentList "$arg1 $arg2"

Hello Kv ^^
You think the error is not comming from the line 53 / 56 but the launch of the script…Oh yes i don’t see it.
I will try and keep you in touch :wink:

Yes it’s much better !!

It was so easy…i’m so stupid lol.

Thx to you :wink:

Now i’have another issue, "Line 1, Could not parse the document : ‘Element not found’

The arg2 is set to “j:\test.ovf”

I think the command line create it self the file.
But i’ve create the file and the error is the same.


As i said it’s better but now the error is :

Start-Process $app -ArgumentList $arg1 $arg2, I have the error :

Start-Process : A positionnal parameter cannot be found that accept argument :'j:\test.ovf'