I tried running this script to install VMtools on VMs. Sometimes "Mount-Tools -VM $VM" doesnt work. It gets timed out in vcenter.
Got this script from another blog.
$VM='testVM01'
## Mounting Datastore
Get-VM -Name $vm | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[BMSDatastore] b583c243-068a-96f3-57fe-3becef1b8201/vmtools/windows.iso'-StartConnected $true -Confirm:$false
##Running command to install Vmtools that is mounted on D:\ inside TestVM01.
Invoke-VMScript -VM $VM -ScriptText {'d:\setup64.exe /s /v "/qn reboot=r"'} -ScriptType Powershell -GuestUser <username> -GuestPassword <pass>
##dismount the CD
Dismount-Tools -VM $VM
Its throwing the error:
mount CD on testVM01
IsoPath HostDevice RemoteDevice
------- ---------- ------------
[BMSDatastore] b...
invoke is running
Invoke-VMScript : 4/12/2023 5:25:16 PM Invoke-VMScript Timeout error while waiting for VMware Tools to start in the guest.
At C:\Users\xyz\Scriptvmtoolinstall.ps1:8 char:1
+ Invoke-VMScript -VM $VM -ScriptText {'d:\setup.exe /s /v "/qn reboot= ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationTimeout: (:) [Invoke-VMScript], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_WaitProcessInGuest_OperationTimeout,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
dismounting
Dismount-Tools : 4/12/2023 5:25:19 PM Dismount-Tools Operation "Dismount VMware Tools" failed for VM "DA2416AMS0013" for the following reason: The operation is not allowed in the current
state.
At C:\Users\xyz\Scriptvmtoolinstall.ps1:11 char:1
+ Dismount-Tools -VM $VM
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Dismount-Tools], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DismountVmTools_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DismountVmTools
Need help.
i need execute this on multiple vms
That is a chicken and egg problem.
To use Invoke-VMScript the targetted VM needs to have VMware Tools installed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah.. thought so..
Do you have any other way where we can automate to install VMtools on the VMs the vmtool not installed.
I dont want to manually RDP to VMs go to the PC, click on the drive on which VMtool iso is mounted, and run the installation wizard.
I want to automate that on multiple VMs. Is there anyway we can achieve that?
Do you have a tool to run commands inside the GUest OS on those VMs?
Or is PowerShell installed in the Guest OS of those VMs and is Remote PS active?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
We do not have a separate tool to run these commands.
We do have windows powershell running in our VMs.
I am trying to run the script from an admin VM remotely to install the tools on all VMs on which tool is not installed.
Then you should be able to use PowerShell Remoting.
See for example Solved: Re: PowerShell remoting to install VMWare tools - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Let me check that out. Thanks man!
For remote powershell to work , the VM has to be accessible in the network. Without VMtools, it seems not possible.
Here is what i did:
It failed, with error:
PS C:\Users\spb920> .\vmtoolinstallscript.ps1
Enter **DOMAIN** password: **************
New-PSSession : [amsdaspb920] Connecting to remote server amsdaspb920 failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer
name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM
firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.
At C:\Users\spb920\vmtoolinstallscript.ps1:11 char:14
+ $RMsession = New-PSSession -ComputerName $VM -Credential $Credentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
4 . Next i did a remote console to my test to check the WInRM config.
This is what i am seeing:
Again, it looks like a chicken and egg situation ![]()
Let me know if missed anything here.
In the about_Remote_Requirements page, you will see that it says (for Public networks).
"To enable remoting on client versions of Windows with public networks, use the SkipNetworkProfileCheck parameter of the Enable-PSRemoting cmdlet. It creates a firewall rule that allows remote access only from computers in the same local subnet."
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
