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

Welcome Forums General PowerShell Q&A VMWare OVF Tool, Script in Powercli with ovtool.exe command in a windows Server

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
5 days, 14 hours ago.

  • Author
    Posts
  • #182283

    Participant
    Topics: 6
    Replies: 24
    Points: 45
    Rank: Member

    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
    clear
     
    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)
    {
    $zone='mycloud.per.zettagrid.com'
    }
    elseif ($answer -eq 2)
    {
    $zone='mycloud.syd.zettagrid.com'
    }
    elseif ($answer -eq 3)
    {
    $zone='mycloud.mel.zettagrid.com'
    }
    else 
    {
    write-host "You choose....poorly"
    exit
    }
     
    # 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
    $vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}"
    
    #Build the vCloud Connection String to Hide Password
    $vCloud2="vcloud://${username}:*******@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}"
     
    write-host "vCloud Connection String" $vCloud2 -ForegroundColor Yellow
    write-host""
     
    # 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):

    $vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}"

    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.

  • #182625

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

    You can use Start-Process for this.

    Start-Process $app -ArgumentList "$arg1 $arg2"
    
  • #182643

    Participant
    Topics: 6
    Replies: 24
    Points: 45
    Rank: Member

    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 😉

  • #182727

    Participant
    Topics: 6
    Replies: 24
    Points: 45
    Rank: Member

    Yes it's much better !!

    It was so easy....i'm so stupid lol.

    Thx to you 😉

    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.

  • #182967

    Participant
    Topics: 6
    Replies: 24
    Points: 45
    Rank: Member

    Hello,

    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'

You must be logged in to reply to this topic.