host vs remote invoke-command

This topic contains 12 replies, has 3 voices, and was last updated by Profile photo of Nghia Tran Nghia Tran 2 years, 6 months ago.

  • Author
    Posts
  • #15809
    Profile photo of Nghia Tran
    Nghia Tran
    Participant

    Hi all,
    Would anyone know why I'm able to execute this command directly on my remote hyper-v vm:
    Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait

    But this fails when I do this on the host machine:

    $session = New-Pssession -ComputerName pc1 -Credential pass1
    Invoke-Command -Session $session -ScriptBlock {Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait}

    Host PC OS: windows server 2012 datacenter
    Remote PC OS: windows 7 (running PSv2)

    Please let me know if you need any other information.

    Thanks in advance!

  • #15816
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    The -Credential parameter needs a credential object, not just a password.


    $session = New-Pssession -ComputerName pc1 -Credential (Get-Credential)

    Verify PowerShell remoting is enabled on the Windows 7 computer named pc1 (it's not enabled by default). Run Enable-PSRemoting on pc1.

  • #15817
    Profile photo of Nghia Tran
    Nghia Tran
    Participant

    Thank you for the reply, but I've already double checked those two variables:
    I was able to do this on my host, which verifies that i can communicate to my pc1.
    Enter-PSSession -ComputerName pc1 -Credential

    i miss-typed my credential from above. I manually enter in my password for now, until i can get a running version.

  • #15818
    Profile photo of Nghia Tran
    Nghia Tran
    Participant

    I'm also using the admin account for both the host and the hyper-v vm...

  • #15819
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    For simplicity, give this a try:

    Create the $session as you previous were, then try this:


    Invoke-Command -Session $session {Start-Process Notepad.exe}

    Then check to make sure notepad is running:


    Invoke-Command -Session $session {Get-Process Notepad}

    • #15820
      Profile photo of Nghia Tran
      Nghia Tran
      Participant

      Yes, that gave me a result with the "ProcessName" of notepad

      Now I'm really lost. Not sure where the disconnect.

  • #15821
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    Can you run the same type of test for the process you're attempting to run?


    Invoke-Command -Session $session -ScriptBlock {Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait}


    Invoke-Command -Session $session -ScriptBlock {Get-Process SomeProgram}

    Note: SomeProgram should be running on the remote machine, but it will not be running interactively in the console.

    • #15823
      Profile photo of Nghia Tran
      Nghia Tran
      Participant

      Yes, this returned a result:

      Invoke-Command -Session $session -ScriptBlock {Get-Process SomeProgram}

      i also see the process running in the IP Address I wanted it to be on. I went a step further and looked at the event log on the VM:

      getting this error: "The description for Event ID 0 from source .NET Runtime cannont be found."

      At least I'm moving forward, I did not get this error when I run the Start-Process directly on the VM... I will have to look up what that error is all about and how it's related to Powershell, if any.

  • #15824
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    Is the same user account being used to start the process locally and remotely?

    • #15825
      Profile photo of Nghia Tran
      Nghia Tran
      Participant

      Yes, the same user account (with admin rights) is being used.

    • #15826
      Profile photo of Nghia Tran
      Nghia Tran
      Participant

      Just so I know I'm not going crazy, I went and reran the code below on my VM directly and it works the way it supposes to.
      Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait\

      Not sure where the disconnect is when I use the invoke-command

      Could this be a UAC issue? I'm trying doing a silent install of my .exe — from what i can tell of my run without the invoke-command the /s should have taken care of any UI and the admin right should take care of an UAC issues that i might encounter... Am I wrong?

  • #15834
    Profile photo of Peter Jurgens
    Peter Jurgens
    Participant

    You may be right about UAC. Only local administrator is never prompted for elevation by UAC, so even if the user account that you are using to start the application is an admin on the machine, by default the computer would still prompt for elevation.

    When you run this code on the VM directly (as you said), does it prompt for elevation?

    Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait
    

    If so, I'd say you have 3 options,
    1) Look into how to change UAC settings so it automatically elevates without prompting.
    2) Try starting the process with the local administrator credentials for the machine.
    3) Examine your installer further. I know a lot of exe installers are just wrappers for an MSI, and if so you may be able to extract the contents of the installer, retrieve the MSI and install using MSIEXEC, which plays much nicer with UAC.

    • #15842
      Profile photo of Nghia Tran
      Nghia Tran
      Participant

      Hi Peter,
      Thank you for your input. I was able to run Start-Process C:\Folder\SomeProgram.exe -ArgumentList /s -Wait directly without any prompts and everything installs just as I expected. My issue is with the Invoke-Command.

      I will give option 3 a try: My installer has a SQL Express 2012 and an .msi in it... at this point I'm willing to try anything 🙂

You must be logged in to reply to this topic.