1

Quick question, have searched for a while but can't find the answer anywhere.

Some background:
I have a local machine and a remote machine (Virtual Machine) that I am connecting through RDP.

I have a batch file that I run that starts the RDP session through Powershell commands and logs in with credentials. My next step is where I run into problems, I have another batch file on the remote machine that I want to run (also Powershell commands).

When I run this batch file physically through the RDP (by either double-clicking or running through the command prompt) all is well.

When I trigger the batch file remotely the batch file runs, but not the way I want. It seems like it runs in the background and not actually showing what it's doing through the RDP session I have. The reason I don't want this running in silent mode is because I have a script that uninstalls and re-installs a program. Since it is not MSI I have to have several "Send Keys" in my code.

So in the end my question is this, can I run a batch file remotely that will act as if I double-clicked the batch file on the remote machine??? I believe that there is an option psexec, but I would prefer not to use any more programs than needed.

3
  • ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
    – kal
    Jan 14, 2015 at 22:18
  • Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
    – Will Webb
    May 18, 2016 at 15:32
  • Have you checked if the batch\powershell script runs under the same user as the user that is currently loged in through the remote session? Jan 10, 2020 at 23:13

1 Answer 1

0

Have you tried Enter-PSSession?

$s = New-PSSession -ComputerName Server01 -Credential Domain01\User01 
# Enter the session yourself
Enter-PSSession -Session $s

or

Invoke-Command -Session $s -ScriptBlock {
    [SCRIPT GOES HERE]
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .