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
LucD,
I found a work around as working as expected.
Is that something, I need to change or is that good
Did you include the class definition as well?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The value you have in $VMname is that the DisplayName of the VM or the FQDN of the guest OS inside the VM?
It needs to be the DisplayName, or a VirtualMachine object (what you get from Get-VM)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You seem to have the FQDN in $vmName
$vmName = 'mypup1.abc.loc'
Try with only the DisplayName
$vmName = 'mypup1'
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
If I use only as the my name mypup1 then I am getting the below error
Invoke-VMScriptPlus : Unable to determine the guest OS type on VM mypup1
At D:\Downloads\Invoke-VMScriptPlus.ps1:616 char:1
+ Invoke-VMScriptPlus @sInvoke
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-VMScriptPlus
Invoke-VMScriptPlus : Try using the GuestOSType parameter.
At D:\Downloads\Invoke-VMScriptPlus.ps1:616 char:1
+ Invoke-VMScriptPlus @sInvoke
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-VMScriptPlus
Resolve-DnsName : 9.3.27.172.in-addr.arpa : DNS name does not exist
At D:\Downloads\Invoke-VMScriptPlus.ps1:211 char:25
+ $hostName = Resolve-DnsName -Name $ip | Select-Object -Ex ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (9.3.27.172.in-addr.arpa:String) [Resolve-DnsName], Win32Exception
+ FullyQualifiedErrorId : DNS_ERROR_RCODE_NAME_ERROR,Microsoft.DnsClient.Commands.ResolveDnsName
Invoke-WebRequest : Cannot bind parameter 'Uri'. Cannot convert value "https://:443/guestFile?id=6&token=52563041-6b65-4013-e236-651a638bf23e6" to type "System.Uri". Error: "Invalid URI: The
hostname could not be parsed."
At D:\Downloads\Invoke-VMScriptPlus.ps1:214 char:50
+ $copyResult = Invoke-WebRequest -Uri $filePath -Method Pu ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ScripText copy failed!Status
At D:\Downloads\Invoke-VMScriptPlus.ps1:217 char:17
+ ... Throw "ScripText copy failed!`rStatus $($copyResult.Statu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (ScripText copy failed!Status :String) [], RuntimeException
+ FullyQualifiedErrorId : ScripText copy failed!Status
What guest OS do you have running in that VM?
Normally, provided the VMware Tools are running, the function can determine the guest OS type.
Try adding the GuestOSType parameter. There are 2 options: Windows or Linux.
The DNS error seems to indicate that your ESXi node does not use a FQDN that is in your DNS.
Is the name of the ESXi node perhaps it's IP address?
Or perhaps you can't query DNS from where you run the script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
After adding the GuestOS type and I tried using different VM, now I am getting the below error
I use IP address for adding my esxi into vcenter. But I am able to query DNS from my laptop where I am running the script
$vmName = 'jivvdjen01'
$credVM = Get-VICredentialStoreItem -Host $vmName
$cred = New-Object System.Management.Automation.PSCredential ($credVM.User, (ConvertTo-SecureString $credVM.Password -AsPlainText -Force))
$sInvoke = @{
VM = $vmName
GuestOS = 'Linux'
GuestCredential = $cred
ScriptText = 'sudo ls -l /opt'
ScriptType = 'bash'
Sudo = $true
}
Invoke-VMScriptPlus @sInvoke
Error:
Resolve-DnsName : 9.3.27.172.in-addr.arpa : DNS name does not exist
At D:\Downloads\Invoke-VMScriptPlus.ps1:211 char:25
+ $hostName = Resolve-DnsName -Name $ip | Select-Object -Ex ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (9.3.27.172.in-addr.arpa:String) [Resolve-DnsName], Win32Exception
+ FullyQualifiedErrorId : DNS_ERROR_RCODE_NAME_ERROR,Microsoft.DnsClient.Commands.ResolveDnsName
Invoke-WebRequest : Cannot bind parameter 'Uri'. Cannot convert value
"https://:443/guestFile?id=12&token=52308dfb-ccda-8daa-2fad-3ee3aeb8db6b12" to type "System.Uri". Error: "Invalid URI:
The hostname could not be parsed."
At D:\Downloads\Invoke-VMScriptPlus.ps1:214 char:50
+ $copyResult = Invoke-WebRequest -Uri $filePath -Method Pu ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ScripText copy failed!Status
At D:\Downloads\Invoke-VMScriptPlus.ps1:217 char:17
+ ... Throw "ScripText copy failed!`rStatus $($copyResult.Statu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (ScripText copy failed!Status :String) [], RuntimeException
+ FullyQualifiedErrorId : ScripText copy failed!Status
The problem here is that the URI the ESXi node returns is using an IP address.
Most of the time the certificates being used, do not contain an entry for the IP address, only the FQDN.
To avoid errors due to that, the function changes the IP address in the URI with the FQDN.
You probably do not have a DNS entry where the hostname is this IP address.
Hence the DNS resolution error.
I could add a switch that cancels that conversion IP to FQDN, just for the cases like yours.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sure LucD. I will wait for your next update.
Try the attached new version of the function.
This version introduces a new switch, name NoIPforCert.
When this switch is $true, the function will not translate the IP address of the ESXi node in the URI to a FQDN.
As a I explained earlier, this might cause errors when using certificates that do not have a SAN entry for the IP address of the ESXi node where the VM is running.
The default is that the IP address is translated to the FQDN.
In your case, you should call the function along these lines.
Note that in the verbose output, you will notice that the GET uses a URI with an IP address in there.
$vmName = 'ubuntuVM'
$credVM = Get-VICredentialStoreItem -Host $vmName
$cred = New-Object System.Management.Automation.PSCredential ($credVM.User, (ConvertTo-SecureString $credVM.Password -AsPlainText -Force))
$sInvoke = @{
VM = $vmName
ScriptType = 'bash'
ScriptText = 'whoami'
GuestCredential = $cred
Verbose = $true
NoIPinCert = $true
}
Invoke-VMScriptPlus @sInvoke
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The blog post, and the attached code in there has been updated with the NoIPinCert switch as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And what do you get when you leave out the NoIPinCert switch?
Keep the Verbose switch in.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My bad, I forgot to adapt the Send-GuestFile function.
Try this attached updated version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And with this version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference