VMware Cloud Community
finkmp
Contributor
Contributor

Invoke-VMScript is not working

Hi all,

Environment:

     vSphere Client Version 6.5.0.13000

     Windows 10 64-bit 1703 Virtual Machines

     4 ESXi Host(s):

          3 are 5.5.0, 6480324,

          1 is 5.5.0, 7967571

    

Problem:

I am trying to use Invoke-VMScript off a a Windows Server 2012 R2 Monitoring Server to send a script to various VMs. I am getting an error message:

pastedImage_2.png

I have opened up port 902 on all of the Virtual Machines but I am still receiving this message and I am not sure what is wrong now as the account I am using has Administrative access to do anything on the VMs, as well as the correct rights in vSphere.

14 Replies
LucD
Leadership
Leadership

From the error message I would think that there 2 possible causes:

  • the account you are using, albeit member of the local administrators group can not execute PowerShell. A quick way to find out, logon to the guest OS and try to start PowerShell. Could be an issue with ExecutionPolicy or the user's profile.
  • your organisation has limited the access to PowerShell. This can be done through a GPO or any other Windows configuration tool. Again, logon locally with that account and try to start PowerShell and execute a cmdlet.


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

finkmp
Contributor
Contributor

Hi LucD,

I have tried the PowerShell Script manually on the device and it works without any issues.

I only have issues when trying to do anything remotely, either with crating a PSSession, Invoke-Command, or Invoke-VMScript. (I know that the first two require different ports, but I wanted to point out the similarity.

Do you have any other ideas on what could be blocking the device? Also do you know where I would need to have ports open, and which ports I would need to have open? (Do I need to open more than port 902, and do I need to have it open on the Monitor Server as well as the VMs?)

Reply
0 Kudos
LucD
Leadership
Leadership

No, that port should be sufficient.
But it doesn't look like a port issue, rather something inside the guest OS and/or the VMware Tools.

Is there anything in the vmware.log for that VM?

What do you mean with the "Monitor Server"?


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

finkmp
Contributor
Contributor

I have a "Monitor Server" that I am running all of my automation scripts from, which is not the vCenter host server so I am using PowerCLI to run the commands remotely.

I am able to run most of the PowerCLI commands, including creating new VMs. I only seem to have an issue connecting with the Guest OS because I couldn't get my OS Cus Specs to work either.

Where is the vmware.log located on the VM?

Reply
0 Kudos
LucD
Leadership
Leadership

In the same folder where the VM's VMX file is located.

In there should be all interactions through the VMware Tools


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

Reply
0 Kudos
finkmp
Contributor
Contributor

I am newish to vmware logging and I don't know where those are located specifically. I found these though:

pastedImage_0.png

Which one should I be looking at, and is there something I should be looking for?

Reply
0 Kudos
finkmp
Contributor
Contributor

Also, I tried adding the computer to the domain to see if that would change anything and there was no difference.

Reply
0 Kudos
finkmp
Contributor
Contributor

I ran the command and then noticed that these 4 lines were added to the "vmware-vmsvc.log" file:

pastedImage_0.png

I am not really sure what they mean though.

Reply
0 Kudos
LucD
Leadership
Leadership

You should be looking in the datastore where the VM is living.
You can find the path of the VMX file by doing

Get-VM | Select Name,@{N='VMX';E={$_.ExtensionData.Config.Files.VmPathName}}

In the Web Client, select the Storage tab, then find the datastore mentioned in the VMX property (see above).

Select that datastore, and click the Files tab.
Now find the VM's folder, select the vmware.log file in that folder and click Download.


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

Reply
0 Kudos
finkmp
Contributor
Contributor

I was able to find the log, but there were no logs created around the time that I "created" the issue. Any other ideas on what might be occurring?

Reply
0 Kudos
finkmp
Contributor
Contributor

I do see that temporary files were created/deleted at the time in which I sent the invoke-vmscript

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership

Can you try to capture a transcript?

Use the code like this (update the password)

$code = @'

Start-Transcript -Path "$env:windir\Temp\log.txt"

Get-ChildItem

Stop-Transcript

'@

Invoke-VMScript -VM $virtualMachine -ScriptText $code -ScriptType Powershell -GuestUser Administrator -GuestPassword 'Your-admin-Password'

On the VM now check if there is a C:\Windows\Temp\log.txt file, and check what is in there.


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

Reply
0 Kudos
finkmp
Contributor
Contributor

I ran the command, which resulted in the same error.

I then checked the machine and a log.txt did not exist in the directory referenced.

I also checked the Events of the VM, and again a file was created then deleted at runtime.

Thank you for continuing to help, I have checked with other parts of our company and this issue seems to be common across multiple departments and nobody has a fix for it, not to say there isn't one but it sounds like there is little hope.

Reply
0 Kudos
LucD
Leadership
Leadership

You could try to get more info in the vmware.log file by enabling the debug option for VMware Tools.

See KB1007873


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

Reply
0 Kudos