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