I experienced similar.
Did the guest credential you used on the Invoke-VMScript already logged on to the guest OS before using the cmdlet?
I assume the guest username is not TEMP?
No as the vm was just created from a template in the same script. I had also tried using administrator. Both fail about 1 out of every 3 times. Is there a way to specify a different location for the file?
I'm afraid not, that's internal to the cmdlet.
I have the impression sometimes it has to do with the user's profile not being completely created yet.
An autologon in the OSCustomizationSpec, when you deploy the vM, for the account avoids the error.
I also sometimes use a Try-Catch, where I intercept the error, and then just try the call again.
Not elegant, but it seems to work.
You could have a look in the VM's vmware.log to check if there any further indications of the cause of the error.