FernGO
Contributor
Contributor

import-vapp remotely

Hello,

Can anyone please confirm if it's possible to use import-vapp remotely?

My environment is vCenter 6.5 and I've tried different powercli versions, 6.3 and 6.5

I'm trying this:

invoke-command -computername $computer {

param ($clus,$vmname,$vmhost,$DC)

                Add-PSSnapin VMware.VimAutomation.Core

                Connect-VIServer vcenter

                foreach ($ds in (Get-DatastoreCluster -Location $DC)) {$Datastore = get-datastore -location $ds.name | Sort FreeSpaceGB -Descending |Select -first 1}

                Import-VApp -source "e:\Win.ova" -location $clus -Name $VMName -vmhost $vmhost -runasync -Datastore $Datastore -DiskStorageFormat Thin

            } -ArgumentList $clus,$vmname,$vmhost,$DC


The process times out after 5 min.

This works perfectly when running locally.


I can't see much in the vmware logs, but I suspect it's certificate related, although I can't prove it.

The connection to the vcenter server is correct, so it's the import-Vapp what it doesn't to be working.


I've configured Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false, and also tried Set-PowerCLIConfiguration -InvalidCertificateAction prompt and run the process in the remote server locally to accept the certificates, but no luck


I've also tried a powershell file in the remote server and ran it as a scheduled task or job, no luck.


Thanks




0 Kudos
6 Replies
kwhornlcs
Enthusiast
Enthusiast

DId you enable remoting on the target computer?

How to Run PowerShell Commands on Remote Computers

if so, you may also be running into an unsigned script issue

Using the Set-ExecutionPolicy Cmdlet

0 Kudos
FernGO
Contributor
Contributor

Yes, I can run other commands, and as I said, it connects to the vCenter server, it can get the datastorage, etc, it's only the import-Vapp part that is not nworkig

Thanks

0 Kudos
kwhornlcs
Enthusiast
Enthusiast

Still looking, unfortunately no access right now to test, but have you tried adding a "-Force"  to the Import-VApp?

Edit: Just noticed you're using add-pssnapin. When you say the script runs fine locally do you mean locally on your machine or when logged on locally to the target. I did have some scripts give weird/failed results on remote machines until I changed the snapins out for modules. In this case, you'd replace "Add-PSSnapin VMWare.VimAutomation.Core" with "Get-Module -ListAvailable VMWare* | Import-Module".

0 Kudos
LucD
Leadership
Leadership

There have been previous mentions of the Import-VApp timing out, see  1.  Re: Import-VApp slow & times out

Unfortunately, no solution for now, unless by calling the API directly.


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

0 Kudos
FernGO
Contributor
Contributor

Thanks for your replies

What I mean is that the script works fine when running locally, everytime I'm logged to my machine or a server, but NOT when running remotely using invoke-command, job or calling it as a scheduled task.

I can run other powerCLI commands remotely using invoke-command with no problems in fact when I run import-vapp remotely, the task is created in vCenter, but doing nothing, and it's "stuck" timing out after 5 min

Nothing gets copied or created in vCenter.

2017-02-27 16_42_24-VMware PowerCLI 6.5 Release 1 build 4624819.png

I tried with -force and same result.

I've tried also loading functions instead of add-pssnapin, same thing

Interestingly it works using PsSession, but not if I use "invoke-command"

Of course I'm using same credentials every time.

Can anyone test if export-vapp works when used remotely using Invoke-command or job?

LucD, I'll check the logs tomorrow in case it's related to the httpNfcLease.

Thanks again

0 Kudos
FernGO
Contributor
Contributor

I've solved this, I was using the -asynchronous  parameter, and when I tried without it, it worked

Thanks to all that replied

0 Kudos