Exporting a VMware VM via PowerCLI (PowerShell) can fail with the following error.

The code I used:

Connect-VIServer vcenter.fqdn
$vm = get-vm -Name 'VMname'

Export-VApp -VM $vm -Format:Ova

This can happen if the certificate of the esxi host when the VM runs on is expired or the chain is not correct.
Of course, the best way is to change, install (if selfsigned) or renew the certificate. But you can also ignore it by adding some extra lines to your PowerShell code.

Connect-VIServer vcenter.fqdn
$vm = get-vm -Name 'VMname'
#ignore SSL part
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()

#End Ignore SSL
Export-VApp -VM $vm -Format:Ova

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *