7 Replies Latest reply on May 17, 2018 9:26 AM by LucD

    Random Invoke-VMScript Failures

    JamieGator32 Novice

      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:




      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




      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





      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.




        • 1. Re: Random Invoke-VMScript Failures
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          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.

          • 2. Re: Random Invoke-VMScript Failures
            JamieGator32 Novice

            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?

            • 3. Re: Random Invoke-VMScript Failures
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              No, no timer, but you could consider that.

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

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

              • 4. Re: Random Invoke-VMScript Failures
                JamieGator32 Novice

                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:




                • 5. Re: Random Invoke-VMScript Failures
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  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)

                  • 6. Re: Random Invoke-VMScript Failures
                    JamieGator32 Novice

                    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!

                    • 7. Re: Random Invoke-VMScript Failures
                      LucD Guru
                      vExpertUser ModeratorsCommunity Warriors

                      You're welcome.

                      Glad you have a solution.