After upgrading the PowerShell module to the latest version now available (11.3.0.13964823), my invoke-vmscript goes wrong. The following exception occurs:
1 2 3 4 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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 |
THANK YOU, I had this exact same issue, you’d think they could be a bit more explicit with the error
Glad i could help
I just started having this error after installing PowerShell 7. I tried uninstalling PowerShell 7 but the error persisted. What is weird is that I get the error but every Invoke-VMScript worked flawlessly other than puking red all over the screen.
Thanks so much for posting this! I was about to go down the rabbit hole.