{"id":700,"date":"2017-07-25T19:48:51","date_gmt":"2017-07-25T18:48:51","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=627"},"modified":"2017-07-25T19:48:51","modified_gmt":"2017-07-25T18:48:51","slug":"running-powershell-script-on-startup","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/windows-10-iot-core\/windows-iot-general\/os-tasks\/running-powershell-script-on-startup","title":{"rendered":"Running PowerShell Script On Startup"},"content":{"rendered":"<h5>\n\tCreate the files<br \/>\n<\/h5>\n<p>\n\tUsing notepad on a desktop PC create the file &quot;MyScript1.ps1&quot; and put the following in it:\n<\/p>\n<pre>\n<code>\n# Store the date and time every startup\n$logFile = &#039;C:\\MyStartupLog.txt&#039;\nget-date &gt;&gt; $logFile\n<\/code><\/pre>\n<p>\n\tNow using notepad create the file &quot;MyStartup.bat&quot; and put the following in it:\n<\/p>\n<pre>\n<code>\npowershell -command &quot;C:\\MyScript1.ps1&quot;\n<\/code><\/pre>\n<h5>\n\tMove the files to the Windows IOT Device<br \/>\n<\/h5>\n<p>\n\tEnable FTP on the device using the SSH command:\n<\/p>\n<pre>\n<code>\nstart C:\\Windows\\System32\\ftpd.exe\n<\/code><\/pre>\n<p>\n\tIn file explorer on your PC in the address bar connect to it using FTP&nbsp;by entering:\n<\/p>\n<p style=\"margin-left: 40px\">\n\tftp:\/\/&lt;your_iot_device_name_or_IP&gt;\n<\/p>\n<p>\n\tDrag the files over.\n<\/p>\n<p>\n\tNow enter the following command to disable ftp again:\n<\/p>\n<pre>\n<code>\nkill ftpd*\n<\/code><\/pre>\n<h5>\n\tEnable remote signed scripts<br \/>\n<\/h5>\n<p>\n\tNext we will need to set the PowerShell execution policy on the Raspberry Pi to allow for remote signed scripts.\n<\/p>\n<p>\n\tConnect using PowerShell (can&#039;t be done via SSH), see <a href=\"https:\/\/ibex.tech\/windows-iot\/windows-iot\/windows-iot-general\/powershell\/connecting-via-powershell\">here<\/a>.\n<\/p>\n<p>\n\tFrom your PowerShell prompt, execute the following command:\n<\/p>\n<pre>\n<code>\nSet-ExecutionPolicy RemoteSigned\n<\/code><\/pre>\n<h5>\n\tCreate a scheduled task to run the script on startup<br \/>\n<\/h5>\n<p>\n\tEnter the following SSH command:\n<\/p>\n<pre>\n<code>\nschtasks \/create \/tn &quot;MyStartupScript&quot; \/tr c:\\MyStartup.bat \/sc onstart \/ru SYSTEM\n<\/code><\/pre>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create the files Using notepad on a desktop PC create the file &quot;MyScript1.ps1&quot; and put the following in it: # Store the date and time every startup $logFile = &#039;C:\\MyStartupLog.txt&#039; get-date &gt;&gt; $logFile Now using notepad create the file &quot;MyStartup.bat&quot; and put the following in it: powershell -command &quot;C:\\MyScript1.ps1&quot; Move the files to the Windows [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[95],"tags":[],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-os-tasks"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":0,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}