VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

issue with Invoke-VMScriptPlus v3

Hi,

I am getting the below error when used the Invoke-VMScriptPlus v3 function

$vmName = 'mypup1.abc.loc'

$credVM = Get-VICredentialStoreItem -Host $vmName

$cred = New-Object System.Management.Automation.PSCredential ($credVM.User, (ConvertTo-SecureString $credVM.Password -AsPlainText -Force))

$sInvoke = @{

    VM = $vmName

    GuestCredential = $cred

    ScriptText = 'sudo ls -l /opt'

    ScriptType = 'bash'

    Sudo = $true

}

Invoke-VMScriptPlus @sInvoke

error :

Invoke-VMScriptPlus : Cannot process argument transformation on parameter 'VM'. Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

At D:\Downloads\Invoke-VMScriptPlus.ps1:621 char:21

+ Invoke-VMScriptPlus @sInvoke

+                     ~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Invoke-VMScriptPlus], ParameterBindingArgumentTransformationException

    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Invoke-VMScriptPlus

0 Kudos
24 Replies
LucD
Leadership
Leadership
Jump to solution

That is most probably a certificate problem, which is something outside the actual function.
Do you have certificates for the ESXi nodes?

Are they self-signed?


There are several solutions to bypass certificate checks on the Invoke-WebRequest.
Several are offered in https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error

You could try one of those, before calling Invoke-VMScriptPlus.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I found a work around as working as expected.

Is that something, I need to change or is that good Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This is a good solution with the current version.

Like I said, bypassing the certificate check for Invoke-WebRequest is something that will probably need to be done outside the function.
The primary reason being that this is something that you can't do more than once in a PS session afaik.
So the function would probably not be the best place unless I test if I can test that.
I'll do some testing to verify if this could eventually be done inside the Invoke-VMScriptPlus function itself.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect LucD.

I will wait for your update.

Thanks a lot for your help and time Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, you use the solution I suggested, and then you mark your answer as the correct one.
Nice, don't think I will answer your future threads anymore.


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

0 Kudos