Quantcast
Channel: Rob V IT
Viewing all articles
Browse latest Browse all 64

Invoke-VMScript: An error occurred while sending the request

$
0
0

After upgrading the PowerShell module to the latest version now available (11.3.0.13964823), my invoke-vmscript goes wrong. The following exception occurs:

Invoke-VMScript : Invoke-VMScript         An error occurred while sending the request.
    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], ViError
    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Finally after a couple hours of troubleshooting, parameter checking and reinstalls we found the issue. The issue is caused by a untrusted certificate of the VMWare VCenter server.

To solve this the “recommended” way: Check and fix your certificates on your system and VCenter server.
The dirty “not recommended” way: Add the following code to your script.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
  public bool CheckValidationResult(
  ServicePoint srvPoint, X509Certificate certificate,
  WebRequest request, int certificateProblem) {
  return true;
  }
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

The post Invoke-VMScript: An error occurred while sending the request appeared first on Rob V IT.


Viewing all articles
Browse latest Browse all 64

Trending Articles