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

 

UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.