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

Deadly 提交于 2019-12-11 13:28:00

问题


We want to make our app to upgrade automatically. Since Windows IOT doesn't have Windows Store we have to do 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 \LocalState\Install.

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

Problem is that we cannot start script as scheduled task and also we cannot run it with powershell -File (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.

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"
            }
      }
}

来源:https://stackoverflow.com/questions/37528256/working-powershell-script-wont-run-as-scheduled-task-windows-iot-rpi-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!