Interactive stuff &  remote PowerShell

Have you ever had the issue that you had to run something on a remote computer? Remote PowerShell is very convenient in these cases. Whenever you need to run something truly interactively though that’s where remote PowerShell stops helping you. If you need something that runs inside a normal interactive session you need an alternative solution. For that I’ve created a PowerShell script.

Run-InteractiveScript allows you to run a PowerShell script in an interactive session on a remote machine utilizing Remote PowerShell to set everything up.

Something I do have to note that this is by no means a secure solution. The script requires plain text credentials and utilizes remote PowerShell to connect to the remote machine (which you can secure using SSL). But it configures the username and password in cleartext in a registry key on the remote machine. The script cleans up after it’s done but the password stays in the registry for the duration of the script that is running on the remote machine.

The script

Run-InteractiveScript.ps1 requires 4 parameters. A remote machine name, a script file path, a username (domain\username format is required) and a password. You can either copy the script from below or download here.

The script consists of 3 parts.

  1. This part configures all requirements on the remote machine. It copies the file to the machine, sets up automatic logon for the specified user and configures your script to start at logon.
  2. The second parts reboots the machine. Waits for the machine to come back online and then waits for the script to finish.
  3. The last part performs the cleanup. It removes all files and registry entries created during the process, logs off the user and finally closes the remote PowerShell session.

Example script execution:

 

Leave a Reply