Hi, I have two questions:
ScriptText parameter explanation is misleading since path to script is not local path but on VM itself which is not good. Invoke-Command cmdlet in PowerShell has this capability - to execute local script on remote machine(s). If I have to copy local PowerShell script to many VMs and then use Invoke-VMScript -ScriptText $pathToLocalps1File it would be an overkill. On the other hand putting large number of commands in string and then use that string as ScriptText is also a bad idea ...
1. Yes (and no).
There is no PowerCLI cmdlet to do that, but you could use PowerShell to connect to the guest OS on the VM and install VMware Tools from there.
It does require PS Remoting being active, and network access.
An alternative is to make the installation of the VMware Tools part of your OS deployment or your cloning OSCustomizationSpec
2. Yes, if you succeeded in doing 1)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If VM does not have VMware Tools installed then it has no network connectivity whatsoever meaning PSRemoting is not doable. Pitty Invoke-VMScript is not as powerful as Invoke-Command in a sense you can not pass local .ps1 script and executed it remotely. Having installed a brand new machine and installed VMware Tools I wanted to execute .ps1 script using Invoke-VMScript (script sets up TCP/IP properties and does many other things) on VM since PSRemoting is impossible because VM has no network connectivity and communication with it is possible only using PowerCLI commands which use VMware Tools.
In that case, use a Template that already has the VMware Tools installed, or install VMware Tools as part of the customisation process (sysprep for Win-based guest OS).
Then Invoke-VMScript will work.
It uses communication through the ESXi node, where the VM is running, and the VM through the VMware Tools interface.
No need to have the VM's guest OS being connected to the network.
But, VMware Tools is essential!
PS: Invoke-Command will not work when there is no PowerShell installed and when remoting is not configured.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference