Create the files

Using notepad on a desktop PC create the file "MyScript1.ps1" and put the following in it:


# Store the date and time every startup
$logFile = 'C:\MyStartupLog.txt'
get-date >> $logFile

Now using notepad create the file "MyStartup.bat" and put the following in it:


powershell -command "C:\MyScript1.ps1"
Move the files to the Windows IOT Device

Enable FTP on the device using the SSH command:


start C:\Windows\System32\ftpd.exe

In file explorer on your PC in the address bar connect to it using FTP by entering:

ftp://<your_iot_device_name_or_IP>

Drag the files over.

Now enter the following command to disable ftp again:


kill ftpd*
Enable remote signed scripts

Next we will need to set the PowerShell execution policy on the Raspberry Pi to allow for remote signed scripts.

Connect using PowerShell (can't be done via SSH), see here.

From your PowerShell prompt, execute the following command:


Set-ExecutionPolicy RemoteSigned
Create a scheduled task to run the script on startup

Enter the following SSH command:


schtasks /create /tn "MyStartupScript" /tr c:\MyStartup.bat /sc onstart /ru SYSTEM

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *