4 Replies Latest reply on Aug 22, 2019 10:06 PM by ganapa2000

    Invoke-command is not working on VM

    ganapa2000 Hot Shot

      Hi,

       

      I am unable to uninstall the application using the invoke-command as below, please help

       

      $serv = Get-Content ".\vms.txt"

      $WPassword = "password"

      $pass = ConvertTo-SecureString -AsPlainText $WPassword -Force

      $Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)

      $output = Invoke-Command -ComputerName $serv -Credential $Creds -ScriptBlock {

      if (Test-Path -Path 'C:\Program Files (x86)\Notepad++\notepad++.exe'){

          echo '32bit installed'

          echo 'Uninstalling x86 Notepad++......'

          & 'C:\Program Files (x86)\Notepad++\uninstall.exe' '/S'

      } elseif (Test-Path -Path 'C:\Program Files\Notepad++\notepad++.exe'){

          echo '64bit installed'

          echo 'Uninstalling 64 bit Notepad++......'

          & 'C:\Program Files\Notepad++\uninstall.exe' '/S'

      } else {

          "Notepad++ is not installed"

      }

      }

      $output

        • 1. Re: Invoke-command is not working on VM
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Is there any output from the Invoke-Command?
          If not, can you add a Start-Transcript to the code block?

          • 2. Re: Invoke-command is not working on VM
            ganapa2000 Hot Shot

            LucD,

             

            Output is

             

            32bit installed

            Uninstalling x86 Notepad++......

             

            But when I login the actual machine, it is not getting uninstalled.

             

            When I execute the below script directly on the remote computer, it works

             

            if (Test-Path -Path 'C:\Program Files (x86)\Notepad++\notepad++.exe'){

                echo '32bit installed'

                echo 'Uninstalling x86 Notepad++......'

                & 'C:\Program Files (x86)\Notepad++\uninstall.exe' '/S'

            } elseif (Test-Path -Path 'C:\Program Files\Notepad++\notepad++.exe'){

                echo '64bit installed'

                echo 'Uninstalling 64 bit Notepad++......'

                & 'C:\Program Files\Notepad++\uninstall.exe' '/S'

            } else {

                "Notepad++ is not installed"

            }

            • 3. Re: Invoke-command is not working on VM
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              This looks to be an issue with UAC.
              You need to run this uninstall from an elevated prompt.

              An alternative could be to have psexec.exe available on the target station.

              • 4. Re: Invoke-command is not working on VM
                ganapa2000 Hot Shot

                LucD,

                 

                Thanks for assisting on this issue, most of the times, psexec gives error because of firewall issues and fails, I was able to resolve as below

                 

                $output = Invoke-Command -ComputerName $serv -Credential $Creds -ScriptBlock {start-process -filepath 'C:\Program Files (x86)\Notepad++\uninstall.exe' -ArgumentList '/S' -Verb runas -Wait}

                 

                As always, thanks a lot for your support and help