VMware Cloud Community
Shru
Contributor
Contributor

How to import a .ova file with disk format as thin provision using Powercli

Hi,

   Have a query wrt importing of a .ova file. The code is as follows...

$AppOVA = "\\10.31.180.198\e$\build\file.ova"
$AppHostName = "App-name"
$AppFQDN = "domain.com"
$AppDS = "LUN1"
$AppIP = "10.30.190.40"
$AppID = "443"
$AppGW = "10.30.190.1"
$AppDNS = "10.30.190.14"
$AppUser = "Admin"
$AppPass = "password"
$vCenter = "10.30.190.150"
$vcUsername = "admin"
$vcPass = "password"
Connect-VIserver -Server $vCenter -User $vcUsername -Password $vcPass
$VMhost = Get-VMHost -Name 10.30.190.236
$Datastore = Get-Datastore -Name $AppDS -VMHost $VMHost
$DiskProvision = Set-HardDisk -StorageFormat "Thin"
Import-VApp -Source $AppOVA -VMHost $VMHost -Datastore $Datastore
Observation: When i try to import the .ova file it trows an error message stating
PowerCLI C:\Users\subras13\Documents\PowerCLI> .\Deploy.ps1
Name                           Port  User
----                           ----  ----
10.30.190.150                  443   root
Import-VApp : 3/18/2012 5:05:02 PM    Import-VApp        Insufficient disk spac
e on datastore 'LUN1'.
At C:\Users\subras13\Documents\PowerCLI\Deploy.ps1:143 char:12
+ Import-VApp <<<<  -Source $AppOVA -VMHost $VMHost -Datastore $Datastore
    + CategoryInfo          : NotSpecified: (:) [Import-VApp], NoDiskSpace
    + FullyQualifiedErrorId : Client20_NfcLease_WaitForNfcLeaseToInitialize_Er
   ror,VMware.VimAutomation.ViCore.Cmdlets.Commands.ImportVApp
By default the disk format is ThickProvisioned. Sizeon disk is 6.5GB for ThinProvisioned and 868.0GB for ThickProvisioned. How do i change the disk format to thin using PowerCli cmdlets and then set the networking properties(IP, gateway,netmask,dns) kindly respond to this at the earliest.
Regards,
Shruthi
Reply
0 Kudos
17 Replies
slaclair
VMware Employee
VMware Employee

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

VCAP5-DCD/DCA/CIA, VCA4-DT
Shru
Contributor
Contributor

Steve,

  I tried executing the following piece of code...

$env:path += ";C:\Program Files\VMware\VMware OVF Tool\"
$vmimportcmd = "ovftool.exe --datastore=" + $AppDS +" --diskMode=thin [$vDPOVA]vi://root:password@10.30.190.236"
Invoke-Expression -Command $vcimportcmd
Have made few changes... vi://root:password@10.30.190.236 - this is the ip address, username and password of my esx. is this correct? what does this ( vi://root:password@10.30.190.236) do?
Observation: Thows an error as follows

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

Reply
0 Kudos
slaclair
VMware Employee
VMware Employee

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)

VCAP5-DCD/DCA/CIA, VCA4-DT
Reply
0 Kudos
Shru
Contributor
Contributor

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

Reply
0 Kudos
slaclair
VMware Employee
VMware Employee

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.

VCAP5-DCD/DCA/CIA, VCA4-DT
Reply
0 Kudos
Shru
Contributor
Contributor

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

$AppOVA = "\\10.31.180.198\e$\build\file.ova"
$AppHostName = "App-name"
$AppFQDN = "domain.com"
$AppDS = "LUN1"
$AppIP = "10.30.190.40"
$AppID = "443"
$AppGW = "10.30.190.1"
$AppDNS = "10.30.190.14"
$AppUser = "Admin"
$AppPass = "password"
$vCenter = "10.30.190.150"
$vcUsername = "admin"
$vcPass = "password"
#Connecting to the vCenter
Connect-VIserver -Server $vCenter -User  $vcUsername -Password $vcPass
#Retrieving the ESX host details in which the .ova has to be deployed
$VMhost = Get-VMHost -Name  10.30.190.236
#Retrieving theDatastore in which the .ova has to be deployed
$Datastore = Get-Datastore -Name $AppDS  -VMHost $VMHost

# 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

Reply
0 Kudos
Shru
Contributor
Contributor

Steve,

   Could you please help me in resolving this issue. This would be really helpful.

Shruthi

Reply
0 Kudos
Shru
Contributor
Contributor

Hi,

   Kindly do respond to this query at the earliest.

Shruthi

Reply
0 Kudos
slaclair
VMware Employee
VMware Employee

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

VCAP5-DCD/DCA/CIA, VCA4-DT
CSIEnvironments
Enthusiast
Enthusiast

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!    

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

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 + ":" + $vcPass

Connect-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.

Reply
0 Kudos
Shru
Contributor
Contributor

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

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

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.

Reply
0 Kudos
Shru
Contributor
Contributor

Kindly respond to the above issue.

Shruthi

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

Relating to your question about a script editor with debuging possibilities for PowerCLI scripts, I would suggest PowerGUI.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
cloudtrainer
Contributor
Contributor

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.

Reply
0 Kudos
cloudtrainer
Contributor
Contributor

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.

Reply
0 Kudos