How to open remote desktop in a script, which runs as windows task?

1

I am trying to import data from a remote server. My current approach is the create a script on the remote server, which is executed every time I log in using remote desktop. When I log in, a network share is mounted into the RDP session, and the script which is executed, copies a directory from the remote server to the mounted network share, thus making this directory locally available.

I want to automate this process, by creating a windows task. This task should log in a user in the remote server (RDP), and thus trigger the script execution. Is this a feasible method? Would it be possible to achieve this in another way?

Kiril

Posted 2014-11-28T08:58:05.090

Reputation: 145

How do you plan to store the credentials needed to make a connection? What privileges do those credentials have on the remote machine? – Vikas Gupta – 2014-11-28T09:16:05.923

I would create an remote.rdp file, and launch it from the script with the credentials saved. The user logging into the remove machine has enough right to execute xcopyand put the file into the mounted share. – Kiril – 2014-11-28T09:17:28.947

Is there a reason why you use a workaround? I would make it possible to connect to the other pc directly through a network share (in combination with VPN if required). Or use FTP if VPN is not available. – LPChip – 2014-11-28T11:01:29.320

The connection is established by VPN, and only port 3389 is allowed to be open in the firewall... – Kiril – 2014-12-02T12:28:52.347

Answers

1

Yes you can write a powershell script to do the needful and from task scheduler by adding action as "Program/Script: Powershell.exe" and argument should me your ps file location. Check the Microsoft link for detailed information on how to execute a powershell script in task scheduler.

Edited:

You can connect remote machine from poweshell using the command

Enter-PSSession -ComputerName computer_name

Steps to establish remote connection using power shell.

vembutech

Posted 2014-11-28T08:58:05.090

Reputation: 5 693

Running the powershell script as a task is the easier part. I am trying to open RDP session using the script, or looking for an alternative approach. – Kiril – 2014-11-28T09:16:10.873

@Kiril, the post has been updated :) – Dave – 2014-11-28T10:01:23.567

This is a really nice approach. I have to check whether the remote server can enable WinRM. Thanks. – Kiril – 2014-11-28T10:06:08.803