VMware Cloud Community
JCayetano
Enthusiast
Enthusiast
Jump to solution

Unable to use some Cmdlets - ERROR Exception has been thrown by the target of an invocation

Hello folks , I am going no where with this .

So , I am unable to get this to work a simple  VM OS restart does not work.

#Restart-VMGuest -vm $VMName -Confirm:$false

   Stop-VM -VM $VMName -Confirm:$false -Kill

   #start-sleep -s 3

   #wait-tools -vm $VMName

   Get-VM -name $VMName

Stop-VM : 5/1/2019 11:37:16 AM    Stop-VM        Exception has been thrown by the target of an invocation.  

At D:\Scripts\vscript\~_remote.ps1:89 char:4

+    Stop-VM -VM $VMName -Confirm:$false -Kill

+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Stop-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.StopVM

Exception has been thrown by the target of an invocation

--- VM info ---

Remote

VM : Win2K16 (Local  plain config)

Pversion: 5.1~

I have to complete the config of a few dozens of  win2k16 vms  and I could not figure out what is missed or  broken. <So far  I have a  workaround on how to complete the config process> but I would like to resolve this sooner than later .

The same behavior happens with an Invoke command and I can't do almost anything.

Invoke-VMScript -VM $VMName -ScriptText $remote_script -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

Invoke-VMScript : 5/1/2019 12:04:49 PM    Invoke-VMScript        Exception has been thrown by the target of an invocation.  

At ~_remote.ps1:94 char:4

+    Invoke-VMScript -VM $VMName -ScriptText $remote_script -GuestUser $GuestCred  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Does any one is  familiar with that Error ?

The only command that I can run so far is the Get -VM . At least I can validate that I am able to connect to the Vcenter lol

Get-VM -name $VMName

Name                    : <VM NAME HERE>

PowerState              : PoweredOn

Notes                   :

Guest                   :

NumCpu                  : 4

CoresPerSocket          : 1

MemoryMB                : 8192

MemoryGB                : 8

VMHostId                :

VMHost                  :

VApp                    :

FolderId                :

Folder                  :

ResourcePoolId          :

ResourcePool            :

HARestartPriority       : ClusterRestartPriority

HAIsolationResponse     : AsSpecifiedByCluster

DrsAutomationLevel      : AsSpecifiedByCluster

VMSwapfilePolicy        :

VMResourceConfiguration : CpuShares:Normal/4000 MemShares:Normal/81920

Version                 :

PersistentId            :

GuestId                 :

UsedSpaceGB             :

ProvisionedSpaceGB      :

DatastoreIdList         :

ExtensionData           : VMware.Vim.VirtualMachine

CustomFields            : {[NB_LAST_BACKUP, ], [SRM-com.vmware.vcDr:::protected, ]}

Id                      : VirtualMachine-vm-80904

Uid                     : /VIServer=VCENTER-HERE/VirtualMachine=VirtualMachine-vm-80904/

Client                  : VMware.VimAutomation.ViCore.Impl.V1.VimClient

Thanks

0 Kudos
1 Solution

Accepted Solutions
JCayetano
Enthusiast
Enthusiast
Jump to solution

Hello LucD ... last week I got stuck on a project and could not follow up on this.

I am currently continue with this investigation    - Found the solution -

Meanwhile I am writing down all my Investigation.

Well , in regards the timestamps on the vmware.log , it seemed to be correct I didn't know until I got confirmation that we are using a different time zone than the EST or CST so the time stamps were okay .

2019-05-04T15:00:17.232Z| vmx| I125: Log for VMware ESX pid=3948922 version=6.7.0 build=build-8941472 option=Release

2019-05-04T15:00:17.232Z| vmx| I125: The process is 64-bit.

2019-05-04T15:00:17.232Z| vmx| I125: Host codepage=UTF-8 encoding=UTF-8

2019-05-04T15:00:17.232Z| vmx| I125: Host is VMkernel 6.7.0

2019-05-04T15:00:17.203Z| vmx| I125: VTHREAD 485383989248 "vmx" wid 3948922

2019-05-04T15:00:17.203Z| vmx| I125: Msg_SetLocaleEx: HostLocale=UTF-8 UserLocale=NULL

Over the weekend I deleted the vm and started from scratch , also I modified a little bit the instructions on the script to resolve the 1st challenge of  2  "the Restart VM command"  this instruction made my weekend:

Get-vm $VMName | Restart-VMGuest -Confirm:$false -ErrorAction SilentlyContinue

Then I re ran 2  commands (Invoke-VMScript and Copy-VMGuestFile) , same problem

1.-  Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell-


Invoke-VMScript : 5/4/2019 9:41:59 AM    Invoke-VMScript        Exception has been thrown by the target of an invocation.   

At ~_Script\~_remote.ps1:354 char:6

+      Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -Gues ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

2.- Get-Item $buildvmfile | Copy-VMGuestFile -Destination $Custps1 -VM $VMName -LocalToGuest -GuestUser $GuestCred -GuestPassword $GuestPass

Copy-VMGuestFile : 5/4/2019 9:42:00 AM    Copy-VMGuestFile        Exception has been thrown by the target of an invocation.   

At ~_remote.ps1:356 char:30

+      Get-Item $buildvmfile | Copy-VMGuestFile -Destination $Custps1 -VM $VMName  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Copy-VMGuestFile], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyVMGuestFile

In regards the debug logs , well  I followed the KB you posted and looks like a new KB should be written for Win2k16  or probably I miss understood the instructions however I could not enable the debug logs.

There is no file location for windows 2016

Windows Vista, Windows 7, Windows 8, Windows Server 2008 and Windows Server 2012C:\ProgramData\VMware\VMware Tools\tools.conf

I opened the windows services to look at the correct path , which was C:/Program Files\VMware\VMware Tools\

at vmware-vmsvc.log I saw the follow socket error:

[May 04 03:41:14.706] [ message] [vmsvc] Log caching is enabled with maxCacheEntries=4096.

[May 04 03:41:15.190] [ message] [vmtoolsd] Tools Version: 10.2.1.4164 (build-8267844)

[May 04 03:41:15.190] [ message] [vmtoolsd] Tools Version: 10.2.1.4164 (build-8267844)

[May 04 03:41:15.190] [ warning] [vmsvc] SOCKET failed to create socket, error 10047: An address incompatible with the requested protocol was used

[May 04 03:41:15.190] [ warning] [vmsvc] SimpleSock: failed to create socket, error 10047: An address incompatible with the requested protocol was used

[May 04 03:41:15.299] [ warning] [hgfsd] HgfsServerClientRedirectorExecOp: Info: Service client redirector op 0

I uninstall the tools again and re install them  and the socket Error is gone

I went and restated the VM  check the vmware.log and I noticed :

2019-05-04T15:56:03.486Z| vmx| I125: VMXVmdb_SetToolsVersionStatus: status value set to 'ok', 'current', install possible

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS installed legacy version 10305, available legacy version 10305

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS manifest update status is 3

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS can be autoupgraded.

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS Setting autoupgrade-checked TRUE.

2019-05-04T15:56:24.742Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 5, assigned to channel 1.

2019-05-04T15:56:24.743Z| vmx| I125: GuestRpc: Got error for channel 1 connection 5: Remote disconnected

2019-05-04T15:56:24.743Z| vmx| I125: GuestRpc: Closing channel 1 connection 5

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 6, assigned to channel 1.

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Got error for channel 1 connection 6: Remote disconnected

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Closing channel 1 connection 6

2019-05-04T15:56:25.777Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 7, assigned to channel 1.

2019-05-04T15:56:25.778Z| vmx| I125: GuestRpc: Got error for channel 1 connection 7: Remote disconnected

2019-05-04T15:56:25.778Z| vmx| I125: GuestRpc: Closing channel 1 connection 7

few minutes later without invoking any command the same errors .

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 95, assigned to channel 1.

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Got error for channel 1 connection 95: Remote disconnected

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Closing channel 1 connection 95

2019-05-04T15:57:55.090Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 96, assigned to channel 1.

2019-05-04T15:57:55.094Z| vmx| I125: GuestRpc: Got error for channel 1 connection 96: Remote disconnected

2019-05-04T15:57:55.094Z| vmx| I125: GuestRpc: Closing channel 1 connection 96

2019-05-04T15:57:56.094Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 97, assigned to channel 1.

2019-05-04T15:57:56.095Z| vmx| I125: GuestRpc: Got error for channel 1 connection 97: Remote disconnected

2019-05-04T15:57:56.095Z| vmx| I125: GuestRpc: Closing channel 1 connection 97

Interesting right?, apparently and based on what the logs are reporting is that any socket that the vm is trying to use just dies .(maybe a bug)

Since the copy command also is not working I have another workaround , it is kinda large code but works .

  Write-Host "`n Transfering the vm file to $VMName"  -ForegroundColor Cyan

    echo "VM Parameter value recived:" $VMName

            

    $vm = Get-VM  $~vm name

          

    $file = Get-Item $vmfile #The path where the file is located to be transfered.

    $destination = " path file.extension "

    echo "Destination path:" $destination

    $force = $true # e.g. overwrite any existing file with this name

    $auth = New-Object VMware.Vim.NamePasswordAuthentication

    $auth.interactiveSession = $false

    $auth.username = "~"

    $auth.password = "~"

    $fileAttributes = New-Object VMware.Vim.GuestFileAttributes

    $guestFileManager = Get-View -Id 'GuestFileManager-guestOperationsFileManager'

    $uploadUrl = $guestFileManager.InitiateFileTransferToGuest($vm.Id, $auth, $destination, $fileAttributes, $file.Length, $force)

    $webClient = New-Object System.Net.WebClient

    $webClient.UploadFile($uploadUrl, "PUT", $file.FullName)

Here are the lines logged at vmware.log

2019-05-04T16:30:58.403Z| vmx| I125: VigorTransportProcessClientPayload: opID=76422a6f-8f-84af seq=34873: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-04T16:30:58.451Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=76422a6f-8f-84af seq=34873: Completed GuestOps request.

and those also were written inside the OS at vmware-vmsvc.log

Then I re ran the commands that we know are having problems however  this time I added something that I did not  that would work actually sounds not necessary but here it is:  Smiley Happy what made me going on this path it is the command that worked on restarting the VM.

$vm= Get-vm <VMname>

     Invoke-VMScript -VM $vm -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

and... whooolaaa!

That made the day

Name                           Port  User                         

----                           ----  ----                         

~ .... 443   ~             

VM           : 

ExitCode     : 0

ScriptOutput : "VMName here"

              

Uid          : /VIServer=use@Vcenter:443/VirtualMachine=VirtualMachine-vm-83197/VMScriptResult=-440305295_0/

Length       : 16

vmware.log logged the follow:

2019-05-04T16:43:44.505Z| vmx| I125: VigorTransportProcessClientPayload: opID=c5740a8-84-8d2c seq=35912: Receiving GuestOps.CreateTemporaryFile request.

2019-05-04T16:43:44.656Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=c5740a8-84-8d2c seq=35912: Completed GuestOps request with messages.

2019-05-04T16:43:44.681Z| vmx| I125: VigorTransportProcessClientPayload: opID=2a4212c1-57-8d33 seq=35923: Receiving GuestOps.StartProgram request.

2019-05-04T16:43:44.705Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=2a4212c1-57-8d33 seq=35923: Completed GuestOps request with messages.

2019-05-04T16:43:44.716Z| vmx| I125: VigorTransportProcessClientPayload: opID=57dd5293-7e-8d39 seq=35934: Receiving GuestOps.ListProcesses request.

2019-05-04T16:43:44.750Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=57dd5293-7e-8d39 seq=35934: Completed GuestOps request with messages.

2019-05-04T16:43:49.765Z| vmx| I125: VigorTransportProcessClientPayload: opID=4f863559-73-8d44 seq=35945: Receiving GuestOps.ListProcesses request.

2019-05-04T16:43:49.885Z| vcpu-3| I125: VigorTransport_ServerSendResponse opID=4f863559-73-8d44 seq=35945: Completed GuestOps request with messages.

2019-05-04T16:43:49.912Z| vmx| I125: VigorTransportProcessClientPayload: opID=784a4273-4-8d4b seq=35956: Receiving GuestOps.InitiateFileTransferFromGuest request.

2019-05-04T16:43:49.942Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=784a4273-4-8d4b seq=35956: Completed GuestOps request with messages.

2019-05-04T16:43:50.109Z| vmx| I125: VigorTransportProcessClientPayload: opID=56b0e5ec-21-8d53 seq=35975: Receiving GuestOps.DeleteFile request.

2019-05-04T16:43:50.121Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=56b0e5ec-21-8d53 seq=35975: Completed GuestOps request.

and finally I had to just call the Copy command Smiley Happy

#Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

Copy-VMGuestFile -Source $buildvmfile -Destination $Custps1 -VM $vm -LocalToGuest -GuestUser $GuestCred -GuestPassword $GuestPass

2019-05-04T16:50:06.169Z| vmx| I125: VigorTransportProcessClientPayload: opID=22b9426b-f0-9184 seq=36512: Receiving GuestOps.ListFiles request.

2019-05-04T16:50:06.246Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=22b9426b-f0-9184 seq=36512: Completed GuestOps request with messages.

2019-05-04T16:50:06.270Z| vmx| I125: VigorTransportProcessClientPayload: opID=30b7909c-c3-918b seq=36523: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-04T16:50:06.299Z| vcpu-1| I125: VigorTransport_ServerSendResponse opID=30b7909c-c3-918b seq=36523: Completed GuestOps request.

Another passed test  .

Invoke-VMScript -VM $vm -ScriptText "ping $Gateway" -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

VM           :

ExitCode     : 0

ScriptOutput :

               Pinging A.B.C.D with 32 bytes of data:

               PING: .....

               PING: ....

Kinda interesting isnt? well , I decided to document all of this so if in case some one in the community is facing this problem they can look at this , unless you would like to add some notes ?

Summary:

Unable to use  Invoke-VMScript , Copy-VMGuestFile , Restart-VMGuest

Cmdlets - ERROR Exception has been thrown by the target of an invocation'

Solution:

Make sure you are using a VM-Object  and not a String

$vm= Get-vm <VMname>

     Invoke-VMScript -VM $vm -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

Have a good week!

Regards.

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

For the Invoke-VMScript cmdlet, do you have the VMware Tools installed and running on that VM?

The empty Guest property seems to indicate you don't


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

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

Yeap , tools up and running

Get-VM -name $VMName| select name, @{Name=“ToolsVersion”; Expression={$_.ExtensionData.Guest.toolsversion}}, @{ Name=“ToolStatus”; Expression={$_.ExtensionData.Guest.ToolsStatus}}

Name         : VM Name

ToolsVersion : 10305

ToolStatus   : toolsOk

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

I also  check the Event viewer logs and nothing has been logged .

At this time I am unable to check the vm logs  I do not have the rights  .

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

I am re installing the vmware tools and will give it a new try , will keep you updated.

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

Name         : VMname

ToolsVersion : 10305

ToolStatus   : toolsOk

Invoke-VMScript : 5/1/2019 2:46:22 PM    Invoke-VMScript        Exception has been thrown by the target of an invocation.  

At ~remote.ps1:95 char:4

+    Invoke-VMScript -VM $VMName -ScriptText $remote_script -GuestUser $GuestCred  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Name                    : VMName

PowerState              : PoweredOn

Notes                   :

Guest                   :

NumCpu                  : 4

CoresPerSocket          : 1

MemoryMB                : 8192

MemoryGB                : 8

VMHostId                :

VMHost                  :

VApp                    :

FolderId                :

Folder                  :

ResourcePoolId          :

ResourcePool            :

HARestartPriority       : ClusterRestartPriority

HAIsolationResponse     : AsSpecifiedByCluster

DrsAutomationLevel      : AsSpecifiedByCluster

VMSwapfilePolicy        :

VMResourceConfiguration : CpuShares:Normal/4000 MemShares:Normal/81920

Version                 :

PersistentId            :

GuestId                 :

UsedSpaceGB             :

ProvisionedSpaceGB      :

DatastoreIdList         :

ExtensionData           : VMware.Vim.VirtualMachine

CustomFields            : {[NB_LAST_BACKUP, ], [SRM-com.vmware.vcDr:::protected, ]}

Id                      : VirtualMachine-vm-80904

Uid                     : /VIServer=~:443/VirtualMachine=VirtualMachine-vm-80904/

Client                  : VMware.VimAutomation.ViCore.Impl.V1.VimClient

Reinstall did not fix the problem

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did or didn't?


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

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

.... Nope did not . Smiley Sad

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

After a while I was able to get a copy of the logs , here is the most recent  from executing:

   Restart-VMGuest -vm $VMName -Confirm:$false

   #Invoke-Command -ComputerName $VMName -ScriptBlock { -FilePath $remote_script } -Credential $credentials

   Invoke-VMScript -VM $VMName -ScriptText $remote_script -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

  

.... Log as follow:

2019-05-01T18:46:12.821Z| vcpu-0| W115: GuestRpc: application toolbox-dnd, changing channel 65535 -> 1

2019-05-01T18:46:12.821Z| vcpu-0| I125: GuestRpc: Channel 1, guest application toolbox-dnd.

2019-05-01T18:46:21.806Z| vmx| I125: VigorTransportProcessClientPayload: opID=8fa9f1b-53-73cd seq=184539: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-01T18:46:21.993Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=8fa9f1b-53-73cd seq=184539: Completed GuestOps request with messages.

2019-05-01T18:48:57.376Z| vmx| I125: VigorTransportProcessClientPayload: opID=611205d6-3b-7541 seq=184753: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-01T18:48:57.523Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=611205d6-3b-7541 seq=184753: Completed GuestOps request with messages.

2019-05-02T00:40:39.389Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 20006, assigned to channel 2.

2019-05-02T00:40:41.445Z| vmx| I125: GuestRpc: Got error for channel 2 connection 20008: Remote disconnected

2019-05-02T00:40:41.445Z| vmx| I125: GuestRpc: Closing channel 2 connection 20008

2019-05-02T13:27:27.768Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T13:31:46.590Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T13:47:52.953Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T14:06:19.329Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T14:07:29.963Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T14:09:56.738Z| svga| I125: MKSScreenShotMgr: Taking a screenshot

2019-05-02T14:15:24.134Z| vmx| I125: VigorTransportProcessClientPayload: opID=32b88312-fe-26d4 seq=278715: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-02T14:15:24.322Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=32b88312-fe-26d4 seq=278715: Completed GuestOps request with messages.

apparently something is dropping the RPC connection, I will wait for your thoughts  

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looking at the timestamps, I think those entries are unrelated.

The log does show that a file was copied to the guest OS.

Was this from a Copy-VMGuestFile or an Invoke-VMScript cmdlet?

It might give more clues when you turn on debugging for VMware Tools.

See KB1007873


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

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

Hello LucD ... last week I got stuck on a project and could not follow up on this.

I am currently continue with this investigation    - Found the solution -

Meanwhile I am writing down all my Investigation.

Well , in regards the timestamps on the vmware.log , it seemed to be correct I didn't know until I got confirmation that we are using a different time zone than the EST or CST so the time stamps were okay .

2019-05-04T15:00:17.232Z| vmx| I125: Log for VMware ESX pid=3948922 version=6.7.0 build=build-8941472 option=Release

2019-05-04T15:00:17.232Z| vmx| I125: The process is 64-bit.

2019-05-04T15:00:17.232Z| vmx| I125: Host codepage=UTF-8 encoding=UTF-8

2019-05-04T15:00:17.232Z| vmx| I125: Host is VMkernel 6.7.0

2019-05-04T15:00:17.203Z| vmx| I125: VTHREAD 485383989248 "vmx" wid 3948922

2019-05-04T15:00:17.203Z| vmx| I125: Msg_SetLocaleEx: HostLocale=UTF-8 UserLocale=NULL

Over the weekend I deleted the vm and started from scratch , also I modified a little bit the instructions on the script to resolve the 1st challenge of  2  "the Restart VM command"  this instruction made my weekend:

Get-vm $VMName | Restart-VMGuest -Confirm:$false -ErrorAction SilentlyContinue

Then I re ran 2  commands (Invoke-VMScript and Copy-VMGuestFile) , same problem

1.-  Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell-


Invoke-VMScript : 5/4/2019 9:41:59 AM    Invoke-VMScript        Exception has been thrown by the target of an invocation.   

At ~_Script\~_remote.ps1:354 char:6

+      Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -Gues ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

2.- Get-Item $buildvmfile | Copy-VMGuestFile -Destination $Custps1 -VM $VMName -LocalToGuest -GuestUser $GuestCred -GuestPassword $GuestPass

Copy-VMGuestFile : 5/4/2019 9:42:00 AM    Copy-VMGuestFile        Exception has been thrown by the target of an invocation.   

At ~_remote.ps1:356 char:30

+      Get-Item $buildvmfile | Copy-VMGuestFile -Destination $Custps1 -VM $VMName  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Copy-VMGuestFile], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyVMGuestFile

In regards the debug logs , well  I followed the KB you posted and looks like a new KB should be written for Win2k16  or probably I miss understood the instructions however I could not enable the debug logs.

There is no file location for windows 2016

Windows Vista, Windows 7, Windows 8, Windows Server 2008 and Windows Server 2012C:\ProgramData\VMware\VMware Tools\tools.conf

I opened the windows services to look at the correct path , which was C:/Program Files\VMware\VMware Tools\

at vmware-vmsvc.log I saw the follow socket error:

[May 04 03:41:14.706] [ message] [vmsvc] Log caching is enabled with maxCacheEntries=4096.

[May 04 03:41:15.190] [ message] [vmtoolsd] Tools Version: 10.2.1.4164 (build-8267844)

[May 04 03:41:15.190] [ message] [vmtoolsd] Tools Version: 10.2.1.4164 (build-8267844)

[May 04 03:41:15.190] [ warning] [vmsvc] SOCKET failed to create socket, error 10047: An address incompatible with the requested protocol was used

[May 04 03:41:15.190] [ warning] [vmsvc] SimpleSock: failed to create socket, error 10047: An address incompatible with the requested protocol was used

[May 04 03:41:15.299] [ warning] [hgfsd] HgfsServerClientRedirectorExecOp: Info: Service client redirector op 0

I uninstall the tools again and re install them  and the socket Error is gone

I went and restated the VM  check the vmware.log and I noticed :

2019-05-04T15:56:03.486Z| vmx| I125: VMXVmdb_SetToolsVersionStatus: status value set to 'ok', 'current', install possible

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS installed legacy version 10305, available legacy version 10305

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS manifest update status is 3

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS can be autoupgraded.

2019-05-04T15:56:03.486Z| vmx| I125: TOOLS Setting autoupgrade-checked TRUE.

2019-05-04T15:56:24.742Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 5, assigned to channel 1.

2019-05-04T15:56:24.743Z| vmx| I125: GuestRpc: Got error for channel 1 connection 5: Remote disconnected

2019-05-04T15:56:24.743Z| vmx| I125: GuestRpc: Closing channel 1 connection 5

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 6, assigned to channel 1.

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Got error for channel 1 connection 6: Remote disconnected

2019-05-04T15:56:24.776Z| vmx| I125: GuestRpc: Closing channel 1 connection 6

2019-05-04T15:56:25.777Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 7, assigned to channel 1.

2019-05-04T15:56:25.778Z| vmx| I125: GuestRpc: Got error for channel 1 connection 7: Remote disconnected

2019-05-04T15:56:25.778Z| vmx| I125: GuestRpc: Closing channel 1 connection 7

few minutes later without invoking any command the same errors .

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 95, assigned to channel 1.

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Got error for channel 1 connection 95: Remote disconnected

2019-05-04T15:57:54.088Z| vmx| I125: GuestRpc: Closing channel 1 connection 95

2019-05-04T15:57:55.090Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 96, assigned to channel 1.

2019-05-04T15:57:55.094Z| vmx| I125: GuestRpc: Got error for channel 1 connection 96: Remote disconnected

2019-05-04T15:57:55.094Z| vmx| I125: GuestRpc: Closing channel 1 connection 96

2019-05-04T15:57:56.094Z| vmx| I125: GuestRpc: Got RPCI vsocket connection 97, assigned to channel 1.

2019-05-04T15:57:56.095Z| vmx| I125: GuestRpc: Got error for channel 1 connection 97: Remote disconnected

2019-05-04T15:57:56.095Z| vmx| I125: GuestRpc: Closing channel 1 connection 97

Interesting right?, apparently and based on what the logs are reporting is that any socket that the vm is trying to use just dies .(maybe a bug)

Since the copy command also is not working I have another workaround , it is kinda large code but works .

  Write-Host "`n Transfering the vm file to $VMName"  -ForegroundColor Cyan

    echo "VM Parameter value recived:" $VMName

            

    $vm = Get-VM  $~vm name

          

    $file = Get-Item $vmfile #The path where the file is located to be transfered.

    $destination = " path file.extension "

    echo "Destination path:" $destination

    $force = $true # e.g. overwrite any existing file with this name

    $auth = New-Object VMware.Vim.NamePasswordAuthentication

    $auth.interactiveSession = $false

    $auth.username = "~"

    $auth.password = "~"

    $fileAttributes = New-Object VMware.Vim.GuestFileAttributes

    $guestFileManager = Get-View -Id 'GuestFileManager-guestOperationsFileManager'

    $uploadUrl = $guestFileManager.InitiateFileTransferToGuest($vm.Id, $auth, $destination, $fileAttributes, $file.Length, $force)

    $webClient = New-Object System.Net.WebClient

    $webClient.UploadFile($uploadUrl, "PUT", $file.FullName)

Here are the lines logged at vmware.log

2019-05-04T16:30:58.403Z| vmx| I125: VigorTransportProcessClientPayload: opID=76422a6f-8f-84af seq=34873: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-04T16:30:58.451Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=76422a6f-8f-84af seq=34873: Completed GuestOps request.

and those also were written inside the OS at vmware-vmsvc.log

Then I re ran the commands that we know are having problems however  this time I added something that I did not  that would work actually sounds not necessary but here it is:  Smiley Happy what made me going on this path it is the command that worked on restarting the VM.

$vm= Get-vm <VMname>

     Invoke-VMScript -VM $vm -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

and... whooolaaa!

That made the day

Name                           Port  User                         

----                           ----  ----                         

~ .... 443   ~             

VM           : 

ExitCode     : 0

ScriptOutput : "VMName here"

              

Uid          : /VIServer=use@Vcenter:443/VirtualMachine=VirtualMachine-vm-83197/VMScriptResult=-440305295_0/

Length       : 16

vmware.log logged the follow:

2019-05-04T16:43:44.505Z| vmx| I125: VigorTransportProcessClientPayload: opID=c5740a8-84-8d2c seq=35912: Receiving GuestOps.CreateTemporaryFile request.

2019-05-04T16:43:44.656Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=c5740a8-84-8d2c seq=35912: Completed GuestOps request with messages.

2019-05-04T16:43:44.681Z| vmx| I125: VigorTransportProcessClientPayload: opID=2a4212c1-57-8d33 seq=35923: Receiving GuestOps.StartProgram request.

2019-05-04T16:43:44.705Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=2a4212c1-57-8d33 seq=35923: Completed GuestOps request with messages.

2019-05-04T16:43:44.716Z| vmx| I125: VigorTransportProcessClientPayload: opID=57dd5293-7e-8d39 seq=35934: Receiving GuestOps.ListProcesses request.

2019-05-04T16:43:44.750Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=57dd5293-7e-8d39 seq=35934: Completed GuestOps request with messages.

2019-05-04T16:43:49.765Z| vmx| I125: VigorTransportProcessClientPayload: opID=4f863559-73-8d44 seq=35945: Receiving GuestOps.ListProcesses request.

2019-05-04T16:43:49.885Z| vcpu-3| I125: VigorTransport_ServerSendResponse opID=4f863559-73-8d44 seq=35945: Completed GuestOps request with messages.

2019-05-04T16:43:49.912Z| vmx| I125: VigorTransportProcessClientPayload: opID=784a4273-4-8d4b seq=35956: Receiving GuestOps.InitiateFileTransferFromGuest request.

2019-05-04T16:43:49.942Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=784a4273-4-8d4b seq=35956: Completed GuestOps request with messages.

2019-05-04T16:43:50.109Z| vmx| I125: VigorTransportProcessClientPayload: opID=56b0e5ec-21-8d53 seq=35975: Receiving GuestOps.DeleteFile request.

2019-05-04T16:43:50.121Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=56b0e5ec-21-8d53 seq=35975: Completed GuestOps request.

and finally I had to just call the Copy command Smiley Happy

#Invoke-VMScript -VM $vmn -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

Copy-VMGuestFile -Source $buildvmfile -Destination $Custps1 -VM $vm -LocalToGuest -GuestUser $GuestCred -GuestPassword $GuestPass

2019-05-04T16:50:06.169Z| vmx| I125: VigorTransportProcessClientPayload: opID=22b9426b-f0-9184 seq=36512: Receiving GuestOps.ListFiles request.

2019-05-04T16:50:06.246Z| vcpu-2| I125: VigorTransport_ServerSendResponse opID=22b9426b-f0-9184 seq=36512: Completed GuestOps request with messages.

2019-05-04T16:50:06.270Z| vmx| I125: VigorTransportProcessClientPayload: opID=30b7909c-c3-918b seq=36523: Receiving GuestOps.InitiateFileTransferToGuest request.

2019-05-04T16:50:06.299Z| vcpu-1| I125: VigorTransport_ServerSendResponse opID=30b7909c-c3-918b seq=36523: Completed GuestOps request.

Another passed test  .

Invoke-VMScript -VM $vm -ScriptText "ping $Gateway" -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

VM           :

ExitCode     : 0

ScriptOutput :

               Pinging A.B.C.D with 32 bytes of data:

               PING: .....

               PING: ....

Kinda interesting isnt? well , I decided to document all of this so if in case some one in the community is facing this problem they can look at this , unless you would like to add some notes ?

Summary:

Unable to use  Invoke-VMScript , Copy-VMGuestFile , Restart-VMGuest

Cmdlets - ERROR Exception has been thrown by the target of an invocation'

Solution:

Make sure you are using a VM-Object  and not a String

$vm= Get-vm <VMname>

     Invoke-VMScript -VM $vm -ScriptText 'hostname' -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Powershell

Have a good week!

Regards.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid I don't agree with your conclusion.
At least not with the version of PowerCLI (11.2) I'm using.
When you are using another version, I would suggest to also try also with 11.2

When I do

$srvName = 'MyServer2016'

$code = @'

(Get-CimInstance -ClassName Win32_OperatingSystem).Version

'@


Invoke-VMScript -VM $srvName -ScriptText $code |

Select -ExpandProperty ScriptOutput

I get back the string '10.0.14393', which corresponds with a Windows 2016 Server.


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

0 Kudos
JCayetano
Enthusiast
Enthusiast
Jump to solution

Well , looks like something is kinda weired,

Nope did not work , I ran your same comand against a Win2k16 guy .

Invoke-VMScript -VM $srvName -ScriptText $code |

Select -ExpandProperty ScriptOutput

Name                           Port  User                         

----                           ----  ----                         

~... 443   ~         

Invoke-VMScript : 5/9/2019 6:47:31 PM    Invoke-VMScript        Exception has been thrown by the target of an invocation.   

At line:12 char:1

+ Invoke-VMScript -VM $srvName -ScriptText $code |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

This is what we are running , Kinda old

Get-PowerCLIVersion; $PSVersionTable | findstr version

PowerCLI Version

----------------

   VMware PowerCLI 6.5 Release 1 build 4624819

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

Key   : PSVersion

Value : 4.0

Name  : PSVersion

I did a lot research and Tests so I came up with that conclusion , meanwhile if  I run your same command against a

a different server

Invoke-VMScript -VM $srvName -ScriptText $code |

Select -ExpandProperty ScriptOutput

Name                           Port  User                         

----                           ----  ----                         

~.... 443   ~             

6.1.7601

It ran OKay , I got the String Value too Which belongs to

Windows Server 2008 R2, SP16.1.7601

Upgrading the CLI at this time was denied by our internal CAB so I have to find a way to get this resolved. Smiley Happy

0 Kudos