Automation

 View Only
  • 1.  Issue with Invoke-VMscript

    Posted Nov 25, 2011 12:05 PM

    Hi,

    I try to use this command in order to launch an application on a remote Virtual machine.

    It seem to work for "command" like get-childitem.

    But i can't launch notepad on the remote virtual machine for example.

    Here is my code

    [code:1]
    # *********** Load VMWare PowerCLI cmdlets **********
    Add-PSSnapin VMware.VimAutomation.Core
    # ***************************************************
    #Connection au serveur Vsphère
    Connect-VIServer -Server 10.251.*.* -User ***** -Password ******
    Invoke-VMScript -ScriptText "c:\windows\notepad.exe" -VM "********" -GuestUser ***** -GuestPassword ******* -scripttype bat                                                                                            
    Disconnect-VIServer -Confirm:$false
    [/code:1]
    I try like this but nothing better
    [code:1]
    $script = 'Invoke-Item "c:\windows\notepad.exe"'
    Invoke-VMScript -ScriptText $script -VM "******" -GuestUser ******* -GuestPassword ******
    [/code:1]
    I don't get any error. The script is just waiting for a virtual machine answer, but nothing happened.
    does someone can help me ?
    thx in advance


  • 2.  RE: Issue with Invoke-VMscript

    Posted Nov 25, 2011 12:20 PM

    Your notepad probably started correctly, but it is running in another session.

    You won't see it in your interactive session you have on the guest.

    Start a Task Manager, you should see the notepad.exe process.

    Kill the notepad process from the Task Manager and you should see the Invoke-VMScript cmdlet return.

    Update:

    When you do

    Get-VM MyVM |
    Invoke-VMScript -guestpassword "pswd" -GuestUser "domain\user" `
    -ScriptText "C:\Windows\system32\notepad.exe"

    the Invoke-VMScript will wait till you kill the notepad process in the guest.

    With

    Get-VM MyVM |
    Invoke-VMScript -guestpassword "pswd" -GuestUser "domain\user" `
    -ScriptText "Invoke-Item C:\Windows\system32\notepad.exe"

    the Invoke-VMScript cmdlet will return immediatly after the Invoke-Item cmdlet returns.