Hi,
Have a query wrt importing of a .ova file. The code is as follows...
Unfortunately no, I had to do my VM imports via OVF Tool. I add the PATH variable, build a string then execute that string as a command and it works like a charm.... Even when pointing it to the absolute path of the ovftool directory I had a bunch of problems until I added the PATH as an environment variable and it went without issue.
$env:path += "; D:\Program Files\VMware\VMware OVF Tool\"
$vmimportcmd = "ovftool.exe --datastore=" + $AppDS +" --diskMode=thin [path to ovf] vi://root:pass@192.168.100.10"
Invoke-Expression -Command $vcimportcmd
Hope this helps!
Steve
Steve,
I tried executing the following piece of code...
PowerCLI C:\Users\subras13\Documents\PowerCLI> .\DeployApp.ps1
Name Port User
---- ---- ----
10.30.190.150 443 root
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is n
ull.
At C:\Users\subras13\Documents\PowerCLI\DeployBuzz.ps1:145 char:27
+ Invoke-Expression -Command <<<< $vcimportcmd
+ CategoryInfo : InvalidData: (:) [Invoke-Expression], ParameterB
indingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
icrosoft.PowerShell.Commands.InvokeExpressionCommand
Shruthi
I'm sorry, there was a typo on my part.. change your invoke-expression line to read
Invoke-Expression -Command $vmimportcmd (it's just executing the string that you constructed above)
vi://root:password@esxhostip just allows you to skip the password prompts (obviously, replace this with the correct credentials to your ESX host or vCenter server)
Sorry, i do not see any change in the line... Invoke-Expression -Command $vmimportcmd. i still see the same error when i execute it.
I have an other query.... Environmental variable path is initialized with the path of ovf.exe($env:path += "C:\Program Files\VMware\VMware OVF Tool\)
$vmimportcmd = "ovftool.exe --datastore=" + $AppDS +" --diskMode=thin [$vDPOVA]vi://root:emclegato@10.30.190.236" -> here the var path is not peing used!! Please chk the above line and let me the whether the syntax is correct?
Shruthi
Shruthi,
If that PATH variable isn't adding then add it manually.
After that I would work on just making really simple ovf strings to execute with the invoke-expression line just to make sure you don't have any syntax or any other minor errors.
$vmimportcmd = "ovftool.exe source vi://desitinationesx"
Invoke-Expression -Command $vmimportcmd
Then start plugging in your variables, this is exactly how one of my deployment scripts that is regularly used is setup though. I'm hoping the thin provisioning capability will be built into Import-VApp in future releases though.
I am clueless... i do not know what is happening.... As per the below code...
$vmimportcmd = "ovftool.exe source vi://desitinationesx"
Invoke-Expression -Command $vmimportcmd
where is the disk being set to thin provisioning???
Will copy the completed code again, Kindly let me know what excatly i need to change.
# Initializing Variables with their respective values
# Added code
$env:path += "C:\Program Files\VMware\VMware OVF Tool\"
$vmimportcmd = "ovftool.exe --source vi://10.30.190.236"
Invoke-Expression -Command $vmimportcmd
Observation: When this is executed the following result is seen
PowerCLI C:\Users\subras13\Documents\PowerCLI> .\DeployBuzz.ps1
Name Port User
---- ---- ----
10.30.190.150 443 root
The term 'ovftool.exe' is not recognized as the name of a cmdlet, function, scr
ipt file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:12
+ ovftool.exe <<<< --source vi://10.30.190.236
+ CategoryInfo : ObjectNotFound: (ovftool.exe:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
After this
$env:path += "C:\Program Files\VMware\VMware OVF Tool\"
$vmimportcmd = "ovftool.exe --source vi://10.30.190.236"
Invoke-Expression -Command $vmimportcmd
Should is include the Import-VApp command to import the .ova file? (Import-VApp -Source $vDPOVA -VMHost $VMHost -Datastore $Datastore)
Shruthi
Steve,
Could you please help me in resolving this issue. This would be really helpful.
Shruthi
Hi,
Kindly do respond to this query at the earliest.
Shruthi
Shruthi
For some reason that line for adding the OVF tool path isn't working like it did for me. Add the path variable manually in windows (computer properties > advanced settings > environment variables ). To test it just type "OVF" at the command line and hit tab, it should complete with ovftool.exe..
Unfortunately this is the only way you're going to be able to import machines with thin provisioned disks at this time.
Steve
Hi,
I will try assist. Please do the following:
1. Type:
$env:path += ";C:\Program Files\VMware\VMware OVF Tool"
2. Then type:
ovftool
Paste the results...
Thanks!
If that works you will see the following:
PS C:\> ovftool
Error: No source or target specified.
Try 'ovftool --help' for more options.
Completed with errors
Few things to note. ovftool does not like UNC paths, with or without spaces. I you need to map the path to an X or Y drive and use that.
Here is the final script that should work for you Shru:
net use x: "\\10.31.180.120\e$\build"
$AppOVA = "x:\file 0.5TB.ova"
$AppHostName = "App-shru"
$AppFQDN = "talisman.com"
$AppDS = "500-LUN"
$AppIP = "10.31.192.46"
$AppID = "443"
$AppGW = "10.31.192.1"
$AppDNS = "10.31.77.151"
$network = "VLANXXX" #replace with your network you will be connecting it to
$pathtocluster = "/DATACENTER/host/CLUSTERNAME" #replace only DATACENTER and CLUSTERNAME...leave /host/ where it is.
$esxhost = "10.31.194.236"
$vCenter = "10.31.194.154"
$vcUsername = "root"
$vcPass = "vmware"
$creds = $vcUsername + ":" + $vcPassConnect-VIserver -Server $vCenter -User $vcUsername -Password $vcPass
$VMhost = Get-VMHost -Name $esxhost
$Datastore = Get-Datastore -Name $AppDS -VMHost $VMhost
$vmimportcmd = "ovftool.exe --datastore=" + $Datastore + " --diskMode=thin --network=" + $network + " --acceptAllEulas " + $AppOVA + " vi://$creds@$vCenter$pathtocluster"
Invoke-Expression -Command $vmimportcmd
I tested the above and it works for me. Once you have it actual import working you can work on the network customization of the vApp.
By giving the following path "C:\Program Files\VMware\VMware OVF Tool"in the cmd prompt, i am able to list the ovftool.exe file.
Output is as expected:
C:\Program Files\VMware\VMware OVF Tool>ovftool.exe
Error: No source or target specified.
Try 'ovftool --help' for more options.
Completed with errors
After this when i execute the code, with the below changes... i still see the same error msg in power cli....
$network = "10.30.190.236" # Have initialized the network with the esx ip "10.30.190.236"where the .ova will be deployed... is this fine?
$pathtocluster = "DCone" #--replace only DATACENTER and CLUSTERNAME...leave /host/ where it is.=> Here i donot have any cluster setup... i have an esx hosted in the virtual center... so have initialized pathcluster with the datacenter name "DCone" is this correct.
Observation: Powercli Output shows
PowerCLI C:\Users\subras13\Documents\PowerCLI> .\DeployBuzz.ps1
System error 85 has occurred.
The local device name is already in use.
Name Port User
---- ---- ----
10.30.190.150 443 root
The term 'ovftool.exe' is not recognized as the name of a cmdlet, function, scr
ipt file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:12
+ ovftool.exe <<<< --datastore=500-LUN --diskMode=thin --network=10.31.194.236
--acceptAllEulas x:\file.ova vi://root:vmware@10.30.190.150
DCone + CategoryInfo : ObjectNotFound: (ovftool.exe:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Have i missed something!
Shruthi
You are missing a few things.
1. Add it to the environment variables so you just need to type ovftool.exe not "C:\Program Files\VMware\VMware OVF Tool\ovftool.exe. You need to get this correct.
2, $network is the network you connecting it to, VLAN400 or whatever network is on the host, not sure if an IP address will work, will test.
3. Will change it for a host only.
4. Don't run it as a script .\DeployBuzz.ps1. Run 1 line as a time as it's easier to debug.
Kindly respond to the above issue.
Shruthi
Relating to your question about a script editor with debuging possibilities for PowerCLI scripts, I would suggest PowerGUI.
I have a same kind of requirement and i was able to follow the instructions. I am getting error while running this command.
#net use x: "\\WIN-UTQAAFM5902\Script"
$AppOVA = "x:\file s42700x8_2_1.ova"
... # rest of the settings from this post
$vmimportcmd = "ovftool.exe --datastore=" + $Datastore + " --network=" + $network + " --acceptAllEulas " + $AppOVA + " vi://$creds@$vCenter$pathtocluster"
Invoke-Expression -Command $vmimportcmd
The output of $vmimportcmd is:
ovftool.exe --datastore= --network=VLAN 98 --acceptAllEulas x:\file s42700x8_2_1.ova vi://administrator:Cisco123!@10.52.213.156/UK/host/Collab-Blades
The Error is:
Error: Unexpected option: x:\file
Completed with errors
I can see the .ova file when i run ls x:\
PS C:\Users\Administrator> ls x:
Directory: X:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/22/2014 12:18 PM 2052 OvaTestFile3.ps1
-a--- 9/21/2014 1:51 PM 441154560 s42700x8_2_1.ova
Any help is really appreciated.
I found the issue. There is a space in my --network value and due to that it was failing.
It was "VLAN 98". I sent that value in quotes, then it worked.