locked
Working powershell script won't run as scheduled task (Windows IOT - RPI 3) RRS feed

  • Question

  • Guys here is problem. We want to make our app to upgrade automatically. Since Windows IOT doesn't have Windows Store we have to do it manually.

    Here is our solution. Our app checks every 7 days if there is new version on our web server. If it is, app download it in folder <APP>\LocalState\Install.

    Next part is powershell script that checks every hour if there are files in that folder. If there are she install them.

    Problem is that we cannot start script as scheduled task and also we cannot run it with powershell -File <script name> (we tried all the options with UnRestricted, Bypass and RemoteSigned, we also signed it).

    Script is ok and does the work when we start it from command line (command .\APPUpdate.ps1).

    Is there any solution? Please help :)

    $items = Get-ChildItem -Path "c:\Data\Users\DefaultAccount\AppData\Local\Packages\"
     
    foreach ($item in $items)
    {
          # if the item is a directory, then process it.
          if ($item.Attributes -eq "Directory")
          {
                if ($item.name -Match "<app name>") {			
    				"Backuping ini files..."
    				$AppPath = "c:\Data\Users\DefaultAccount\AppData\Local\Packages\" + $item + "\LocalState"
    				$AppName = $item
    				cp "$AppPath\*.ini" "C:\Data\Users\Administrator\Temp"
    				
    				$path1 = "c:\Data\Users\DefaultAccount\AppData\Local\Packages\" + $item.name + "\LocalState\Install\"
    				$path = Get-ChildItem -Path $path1			
    				$dependencies1 = $path1 + "Dependencies\ARM\"
    				$dependencies = Get-ChildItem -Path $dependencies1				
    				"Dependencies..."
    				foreach ($dependency in $dependencies)
    				{
    					  if ($dependency.Attributes -ne "Directory")
    					  {
    							"***** Installing: " + $dependency
    							Add-AppxPackage -ForceApplicationShutdown $dependencies1$dependency					  }
    				}
    				
    				"APP update..."
    				foreach ($p in $path)
    				{
    					  # if the item is NOT a directory, then process it.
    					  if ($p.Attributes -ne "Directory")
    					  {
    						if ($p.name -Match "appxbundle") {
    							"***** Installing: " + $p
    							Add-AppxPackage -ForceApplicationShutdown $path1$p					
    						}	
    					  }
    				}		
    				
    				"Removing install files..."
    				rm $path1\* -Recurse
    				
    				"Restoring ini files..."
    				cp "C:\Data\Users\Administrator\Temp\*.ini" "$AppPath\"
    				
    				"Setting APP as default app"
    				IotStartup add headed $AppName
    				"Done"
    			}
          }
    }

    • Edited by VeljaNi Thursday, June 2, 2016 4:47 PM
    • Moved by Bill_Stewart Monday, July 11, 2016 3:08 PM This is not "reproduce my environment and debug/fix my script for me" forum
    Thursday, June 2, 2016 4:47 PM

Answers

  • For us to help, we would need to reproduce your environment. I suggest a support engagement with Microsoft to help you debug.

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Monday, July 11, 2016 3:07 PM
    Thursday, June 2, 2016 5:57 PM

All replies

  • If the script works from a PowerShell prompt, then you don't have a scripting problem but rather a Task Scheduler problem. Ask your question in the forum relevant to the Windows OS version you are using.

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 2, 2016 4:53 PM
  • But, I need run do this script every day. The app will be free to download so update off app will be the problem. 90% of RPI users would have problems with update over Windows IOT web page...

    Is there any way to do it? It can be different approach, doesn't matter.

    Basically I need way to update my app every time it put install files in some folder on RPI.


    • Edited by VeljaNi Thursday, June 2, 2016 5:18 PM
    Thursday, June 2, 2016 5:00 PM
  • Again: Not a scripting question.

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 2, 2016 5:17 PM
  • Windows IOT is a limited version of Windows.  It may have issues with you script.  You also note that the script won't run from command line.  Perhaps you do not have PowerShell support installed on IOT.


    \_(ツ)_/

    Thursday, June 2, 2016 5:23 PM
  • Bill, when I run .\AppUpdate.ps1 everything works. When I run

    Powershell -file (or -command) AppUpdate.ps1 it stops (just freeze) at line

    Add-AppxPackage -ForceApplicationShutdown $dependencies1$dependency	

    so I think it is script problem, isn't it?

    Thursday, June 2, 2016 5:32 PM
  • Ok, jrv, what woud be proper way to add/update or rewrite (if you like) app using powershell script on Windows 10? I can try it on RPI 3... This script works on command prompt, but fails when I run powershell command with script name as parameter.
    Thursday, June 2, 2016 5:36 PM
  • I agree. You have a bug in your script.  You don't knw how to debug it. We cannot access your system.

    Start by trying t simplify and run until you isolate the issue.

    This line makes no sense -> $dependencies1$dependency

    What is the variable $dependencies1?  I do not see it defined anywhere.


    \_(ツ)_/

    Thursday, June 2, 2016 5:44 PM
  • Ok, lets try this way:

    				foreach ($dependency in $dependencies)
    				{
    					  if ($dependency.Attributes -ne "Directory")
    					  {
    							"***** Installing: " + $dependency
    							"Add-AppxPackage -ForceApplicationShutdown $dependencies1$dependency"
    							Add-AppxPackage -ForceApplicationShutdown $dependencies1$dependency					  }
    				}

    gives output:

    Dependencies...
    ***** Installing: Microsoft.NET.Native.Framework.1.3.appx
    Add-AppxPackage -ForceApplicationShutdown c:\Data\Users\DefaultAccount\AppData\Local\Packages\AHIS_672qw8fpr4s0a\LocalState\Install\Dependencies\ARM\Microsoft.NET.Native.Framework.1.3.appx
    ***** Installing: Microsoft.NET.Native.Runtime.1.3.appx
    Add-AppxPackage -ForceApplicationShutdown c:\Data\Users\DefaultAccount\AppData\Local\Packages\AHIS_672qw8fpr4s0a\LocalState\Install\Dependencies\ARM\Microsoft.NET.Native.Runtime.1.3.appx
    ***** Installing: Microsoft.VCLibs.ARM.14.00.appx
    Add-AppxPackage -ForceApplicationShutdown c:\Data\Users\DefaultAccount\AppData\Local\Packages\AHIS_672qw8fpr4s0a\LocalState\Install\Dependencies\ARM\Microsoft.VCLibs.ARM.14.00.appx
    Works with call .\AppUpdate, fails at Add when call powershell -File or -Command

    Thursday, June 2, 2016 5:56 PM
  • For us to help, we would need to reproduce your environment. I suggest a support engagement with Microsoft to help you debug.

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Monday, July 11, 2016 3:07 PM
    Thursday, June 2, 2016 5:57 PM
  • Works with call .\AppUpdate, fails at Add when call powershell -File or -Command

    You do not say how it fails. You also have not answered my question. 

    Who wrote this script? 

    How are you getting the posted output?  You have no code that would output those lines.

    As Bill has noted, we cannot reproduce your system.  You need to learn how to debug or contact MS Support for help.


    \_(ツ)_/

    Thursday, June 2, 2016 6:16 PM
  • Read this:

    https://www.reddit.com/r/PowerShell/comments/1lc5t5/signing_powershell_scripts_what_do_you_do

    Tuesday, May 8, 2018 1:43 AM