Search code examples
powershellpowershell-remotinginvoke-command

Remote Powershell script fails to install .exe


EDIT2: **After much testing and reading I've realised this is a powershell limitation "environmental snag." (read more here). I've resolved the issue by running the .exe as a task via schtasks.exe **

EDIT: After much testing the problem seems to occur from a difference between a remote PowerShell and a local PowerShell... Problem is still not solved, so any help is more than welcomed!

I'm trying to do something rather simple, which is just not working for me.

I have 2 machines, MachineA and MachineB. Both running PowerShell v2 and are trusted sources of each other with enabled remoting.

I'm trying to run a script on MachineB through MachineA via this command:

invoke-command -computername MachineB { C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass Script.ps1 }

The script itself tries to install an .exe file that has a silent installation option (based on a config file in its directory):

$arguments = "-i silent"
$InstallerPath = "Setup.exe" 
Start-Process $InstallerPath5 $arguments5 -verb runas

When I run the script locally on MachineB - all works fine and installation finishes successfully. However, when I run the script remotely (with the 1st command from MachineA) it just finishes instantly and nothing happens - the installers don't open in the task manager on MachineB at all. No error is produced and no logs.

Funnily enough, when I change the actual script to "& C:\Windows\system32\cmd.exe /c Setup.exe -i silent" and run it remotely the setup starts up, works for 5-6 seconds on 50% cpu utilisation and then goes to 0% and hangs forever. Again, if I run it locally it all works perfectly...

If tried:

  • Running the installer remotely directly (e.g. via invoke-command { & Setup.exe -i } )
  • Editing the script to run without Start-Process ( e.g. & Setup.exe -i)
  • Moving the script to MachineA and running it remotely to MachineB (e.g. invoke-command -filename sciprt.ps1 -computername MachineB)

All of these work if I do it locally on MachineB, but none work if done remotely via MachineA (with different problems though)? I'm going crazy.

I also checked if the remoteshell has admin rights via this:

([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

It returns True. Plus, I can remotely edit the HKLM registry so I assume its working.

Any ideas are more than welcomed at this point!


Solution

  • After much testing and reading I've realised this is a powershell limitation "environmental snag." (read more here). I've resolved the issue by running the .exe as a task via schtasks.exe