VMware Cloud Community
Darkroom
Contributor
Contributor

Deploy OVF template using Import-vApp -Source from Datastore?

I get errors when trying to deploy a ovf template using powercli. I don't want to drag the file across the network every time I need to deploy a vm so I copied the ova file to a datastore.

Copy-DatastoreItem -Item z:\Win2012_R2_Std.ova -Destination vDATA:\temp\ -Force

This works from my desktop using my local storage or a UNC path

Import-vApp -Source "C:\ovas\Win2012_R2_Std.ova"

Import-vApp -Source "\\myfileserver\ovas\Win2012_R2_Std.ova"

This does not work when trying to reach the datastore

Get-Datastore datastore2 | New-DatastoreDrive -Name vDATA:\temp

Import-vApp -Source "vDATA:/temp/Win2012_R2_Std.ova"

Nor does this

Import-vApp -Source "vDATA:\temp\Win2012_R2_Std.ova"

0 Kudos
15 Replies
LucD
Leadership
Leadership

Afaik that is not a PowerCLI limitation, but a vSphere API limitation.

Does it work when you use the URL to the file on the datastore ?

You can create that URL as follows (thanks for William's post named How to Deploy an OVF Located On ESXi Datastore Using ovftool)

$fileName = '[myDS] folder/file.ovf'

$dsName,$filePath = $fileName.Split(']')

$dsName = $dsName.TrimStart('[')

$filePath = $filePath.TrimStart(' ')

$ds = Get-Datastore -Name $dsName

$dcPath = $ds.DatastoreBrowserPath.Split('@')[1].TrimStart('443\').Trimend("\$($dsName)").Replace('\','/')

$url1 = "$($global:DefaultVIServer.ServiceUri.OriginalString.TrimEnd('/sdk'))"

$url2 = "$($filePath)"

$url3 = "dcPath=$($dcPath)"

$url4 = "dsName=$($dsName)"

$url = "$($url1)/$($url2)?$($url3)&$($url4)"

$url


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

Thanks for the reply LucD. When I try to reach it through https from a browser I can see the file. When I try to use it in the script it fails. If I use the GUI to deploy the OVA and in the path if I use the URL to the datastore it works.

PowerCLI C:\> $myDatastore = Get-Datastore -Name "Datastore2"

PowerCLI C:\> $vmHost = Get-VMHost -Name "$newHost"

PowerCLI C:\> $vmHost | Import-vApp -Source "https://10.0.99.248/folder/temp/Win2012_R2_Std.ova?dcPath=ha%252ddatacenter&dsName=datastore2" -Name test01 -Datastore $myDatastore -Force

Import-VApp : Cannot bind parameter 'Source' to the target. Exception setting "Source": "Cannot find drive. A drive with the name 'https' does not exist."

At line:1 char:31

+ ... App -Source "https://10.0.99.248/folder/temp/Win2012_R2_Std.ova?dcPat ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : WriteError: (:) [Import-VApp], ParameterBindingException

    + FullyQualifiedErrorId : ParameterBindingFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.ImportVApp

0 Kudos
LucD
Leadership
Leadership

That looks like a limitation of the cmdlet.

You could try to use the API method directly, there you can specify a URL


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

What's the preferred way to deploy multiple virtual machines without having to drag an ovf or ova across the wire for each spinup? I want to copy the template over the wire one time to the datastore and spin up from there.

0 Kudos
LucD
Leadership
Leadership

Can't you create a template on the destination, and create the VMs from the template


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

I'm new to VMware coming from the Hyper-V world. Do you mean use the New-Vm cmdlet and fetch a ovf file? I have 2 directories with ova and ovf and joining files on the datastore.

0 Kudos
Darkroom
Contributor
Contributor

Looking up the documentation vSphere PowerCLI Reference

Template Template Specifies the virtual machine template you want to use for the creation of the new virtual machine. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release. I'm using PowerCLI 6.3.

0 Kudos
LucD
Leadership
Leadership

No, just wondering why you are using OVF files.

Are these appliances, or do you package VMs you created this way ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

I tried with an OVA file also. We can use either or. I tried to export both types and when I use the switch -Source on the datastore to find those files it fails.

0 Kudos
LucD
Leadership
Leadership

No, I wasn't asking about OVF or OVA, just wondering why you are using OVF to deploy VMs.

Is that a requirement ?

Are the VM appliances packaged in OVF/OVA ?

Do you create those VM in another location, and then package them yourself into an OVF/OVA ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

Our field offices usually get a host that needs 4-8 VMs. DC, file, print dhcp etc... Right now I think it's a process thing. How my predecessor deployed VMs on a single host by using the vSphere client. He would use click file > deploy ovf template > point to ova file. Then once the first is setup he copies the directories on the datastore for the other vms. I think someone created a vm with all of our settings, license, etc... then sysprep'd it, then exported it to be used as a template in the ova format for that first deployment to the site.

I'm attempting to automate a lot of this.

0 Kudos
LucD
Leadership
Leadership

Ok, I see.

So, you would need to copy the VM (in OVF) at least once of the network.

And the VM inside the OVF is used as a template from which to clone all required VMs in the remote site.

Is my assumption correct ?

If yes, then I don't see the point of copying it to the remote datastore as an OVF file.

Just deploy the "template" VM from the OVF file (one transfer over the network).

All subsequent VMs in the remote site can be cloned from this "template" VM (it does seem to be sysprepped).

And that happens locally on the remote server.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Darkroom
Contributor
Contributor

Yes you are correct. So I need to look through documentation on powercli and cloning then? This assumes I can use vCenter I think because at the host I can't clone. Does powercli connect to vCenter or the host when the script runs? Thanks again for the replies and direction.

0 Kudos
Darkroom
Contributor
Contributor

Okay so I tried to deploy the ovf first with the name Test. Then I ran the below command and it failed with

$vm2 = New-VM -Name VM2 -VM Test -Datastore $myDatastore -VMHost $vmHost

Creates a new virtual machine named VM2 by cloning the VM1 virtual machine on the specified datastore and host.

PowerCLI C:\> $vm2 = New-VM -Name VM2 -VM "Test" -Datastore $myDatastore -VMHost $vmHost

New-VM : 6/17/2016 3:42:11 PM    New-VM        The operation for the entity Test failed with the following message: "The operation is not supported on the object."

At line:1 char:8

+ $vm2 = New-VM -Name VM2 -VM "Test" -Datastore $myDatastore -VMHost $v ...

+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VM], NotSupported

    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

0 Kudos
LucD
Leadership
Leadership

The Connect-VIServer cmdlet connects to whatever vSphere Server (vCenter or ESXi) you pass on the Server parameter.

And yes, for the cloning you will need to connect to the vCenter.

Although you can clone a VM without a vCenter as well.

See my HL Tools – Part 1 – Clone a VM without vCenter post.

On the error you receive on the New-VM, sometimes this is caused by an issue in the PowerShell session.

Can you try closing and restarting your PowerCLI session ?

Another reason might be that the target ESXi is running under a "free" license.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos