Hello folks , I am stuck
I am running a simple command
Import-Module "VMware.VimAutomation.Core"
Connect-VIServer something.something.vcenter1
$vms = Import-CSV D:\Scripts\~\adhoc.csv
foreach ($vm in $vms){
$vmn = $vm.vmname
Invoke-VMScript -vm $vmn -ScriptText "ping something.something" -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Bat
}
I am getting the follow error:
Invoke-VMScript : 3/5/2019 7:45:31 PM Invoke-VMScript Exception has been thrown by the target of an invocation.
At D:\Scripts\~\dr_adhoc.ps1:90 char:9
+ Invoke-VMScript -vm $vmn -ScriptText "ping something.something" -GuestU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
If I run the same command on a non windows 2016 it works without any problem I am curios if it is something else
I wish I could get the vmware logs but I couldn't . While working remote the proxy is blocking the downloads
I got it resolved by:
$password = ConvertTo-SecureString -AsPlainText $GuestPass -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $GuestCred,$password
Then inside the for each cycle loop I added :
$text = Invoke-command -ComputerName $vmn -ScriptBlock { ping A.B.C.D } -Credential $credential
echo $text
I hope in the future someone have a workaround to use the Invoke-VMScript
Did you already check the vmware.log of that VM for additional information?
Anything in the event logs on box?
Does the same happen when you change the ScriptType to PowerShell?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I wish I could get the vmware logs but I couldn't . While working remote the proxy is blocking the downloads
I got it resolved by:
$password = ConvertTo-SecureString -AsPlainText $GuestPass -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $GuestCred,$password
Then inside the for each cycle loop I added :
$text = Invoke-command -ComputerName $vmn -ScriptBlock { ping A.B.C.D } -Credential $credential
echo $text
I hope in the future someone have a workaround to use the Invoke-VMScript
The only problem with Invoke-Command is that you rely on the fact that network connectivity to the guest OS is open.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't remember the exact error but I remember an issue where if you didn't have a valid certificate on the vm you couldn't use the Invoke-VMScript
Sounds interesting about the valid cert. I will try to dive into that .
I got all of this "Exception" resolved in another post where I had the same problem and I really needed the Invoke-VMScript to work ..
Unable to use some Cmdlets - ERROR Exception has been thrown by the target of an invocation inVMware PowerCLI