VMware Cloud Community
JamieGator32
Enthusiast
Enthusiast

Random Invoke-VMScript Failures

We utilize a powercli script to deploy virtual machines (servers) in our environment and have been using this script for the past 2 years without much issue.  At the very end of the deployment script I use Invoke-VMScript to install programs and make configuration changes in the registry etc.

A few people on my team use this script and noticed that they are seeing failures now on some Invoke-VMScript commands.  Each time it is not necessarily the same part of the script of than it is while running the Invoke-VMScript command.

Here are some examples of the failures and the respective script I am running:

1.

pastedImage_0.png

Write-Verbose -Message 'Installing Ivanti' -Verbose

# This scriptblock is used to install Ivanti with the Patch module enabled

$InstallIvanti = 'C:\ServerBuild\Ivanti\IvantiInstall.bat'

Invoke-VMScript -ScriptText $InstallIvanti -VM $Global:VMName -GuestCredential $Global:ConfigCred -ScriptType Bat

2.

pastedImage_1.png

Write-Verbose -Message 'Enabling PowerShell Remoting' -Verbose

# This scriptblock is used to enable PS Remoting

$EnablePSRemoting = 'Enable-PSRemoting -force'

Invoke-VMScript -ScriptText $EnablePSRemoting -VM $Global:VMName -GuestCredential $Global:ConfigCred -ScriptType Powershell

3.

pastedImage_4.png

This script has been run on Windows 7 and Windows 10 and the same errors seem to happen.

Any help with troubleshooting would be greatly appreciated.

Thanks,

James

James F Cruce VCP6.5-DCV Gainesville VMUG Leader http://vmug.com/gainesville @jamescruce http://astgl.com
0 Kudos
7 Replies
LucD
Leadership
Leadership

I have seen something similar with new installations.

The reason I had the issue was that it was the first time the user logged on the OS, and that had as an effect that the user profile was being created.

We bypassed the problem by first doing a kind of dummy Invoke-VMScript with the same account.

That way we were sure the user profile was created on the 2nd call to Invoke-VMScript.


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

0 Kudos
JamieGator32
Enthusiast
Enthusiast

Thanks for the quick reply.  What is weird is that some of the Invoke-VMScript commands will work and then they randomly fail.

I will add a dummy Invoke-VMScript at the start of the configuration changes and see if that helps.

Did you put in a timer to give the profile more time to create?

James F Cruce VCP6.5-DCV Gainesville VMUG Leader http://vmug.com/gainesville @jamescruce http://astgl.com
0 Kudos
LucD
Leadership
Leadership

No, no timer, but you could consider that.


First give it a try, do the dummy Invoke-VMScript, 'sleep' (the cmdlet I mean :smileygrin:) for a bit, then do the other Invoke-VMScript calls.

Repeat for a number of VMs and check if the intermittent issue goes away.


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

0 Kudos
JamieGator32
Enthusiast
Enthusiast

Unfortunately it is still happening.  I still can't get it to fail in a consistent way.  It just randomly fails as it runs each Invoke-VMScript command.

I'm going to try looking at my images and possibly rebuild them to see if they still have this issue.

Any ideas are appreciated.

Here is some examples that just happened:

pastedImage_0.png

pastedImage_1.png

James F Cruce VCP6.5-DCV Gainesville VMUG Leader http://vmug.com/gainesville @jamescruce http://astgl.com
0 Kudos
LucD
Leadership
Leadership

Which PowerCLI version are you using?

Perhaps it is useful to try upgrading when you're not at the latest 10.1.0 version.

The Invoke-VMScript cmdlet stores the script that needs to be executed inside the guest OS in a temporary file.

For one reason or another in some cases this files seems to be removed (or not created).
If you're adventurous, you could try using Process Explorer to see who and when these temp file are created/removed.

But as a first measure I would upgrade to the latest PowerCLI version.

And perhaps also the latest PowerShell version (5.1)


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

0 Kudos
JamieGator32
Enthusiast
Enthusiast

I am using 10.1.0 build 8346946. I think I have resolved the issue by going at it from a different angle.  Instead of using a domain credentialed account for the Invoke-VMScript, I am using the built-in Administrator account to perform the Invoke-VMScript commands.  So far after 5 vm deployments it appears to have fixed the issue.

After you mentioned you had seen it before and a timer might work I tried that but it didn't seem to make a difference.  I decided to just use the local administrator account since it wouldn't have the same issues as a newly created profile would.

Thanks so much for your help!

James F Cruce VCP6.5-DCV Gainesville VMUG Leader http://vmug.com/gainesville @jamescruce http://astgl.com
0 Kudos
LucD
Leadership
Leadership

You're welcome.

Glad you have a solution.


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

0 Kudos