Automation

 View Only
  • 1.  Need help in installing VMtools on VMs using powercli

    Posted Apr 12, 2023 04:44 PM

    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

     

     



  • 2.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 12, 2023 05:05 PM

    That is a chicken and egg problem.

    To use Invoke-VMScript the targetted VM needs to have VMware Tools installed.



  • 3.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 13, 2023 11:43 AM

    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?



  • 4.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 13, 2023 12:05 PM

    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?



  • 5.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 13, 2023 03:41 PM

    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.



  • 6.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 14, 2023 05:09 AM

    Then you should be able to use PowerShell Remoting.
    See for example Solved: Re: PowerShell remoting to install VMWare tools - VMware Technology Network VMTN



  • 7.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 21, 2023 08:51 AM

    Let me check that out. Thanks man!



  • 8.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 25, 2023 05:20 PM

    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:

    1. WinRM is disabled by default in our environment.
    2. I enabled it on my test machine. I Tested it and it worked!
    3. Then, i uninstalled VMtools on that machine, just to test out if i can install vmtools iusing remote powershell feature.

    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:

    Saswati_vmware_1-1682442984208.png

    Again, it looks like a chicken and egg situation

    Let me know if missed anything here.



  • 9.  RE: Need help in installing VMtools on VMs using powercli

    Posted Apr 25, 2023 05:33 PM

    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."