Automation

 View Only
  • 1.  import-vapp remotely

    Posted Feb 26, 2017 11:30 PM

    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






  • 2.  RE: import-vapp remotely

    Posted Feb 27, 2017 12:12 AM

    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



  • 3.  RE: import-vapp remotely

    Posted Feb 27, 2017 01:09 AM

    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



  • 4.  RE: import-vapp remotely

    Posted Feb 27, 2017 02:27 AM

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



  • 5.  RE: import-vapp remotely

    Posted Feb 27, 2017 11:14 AM

    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.

    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



  • 6.  RE: import-vapp remotely

    Posted Feb 27, 2017 06:01 AM

    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.



  • 7.  RE: import-vapp remotely

    Posted Mar 31, 2017 03:52 AM

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

    Thanks to all that replied