I'm hoping that someone can help with this Scheduled Task/Powershell issue I'm having as I'm a little stumpted.
First off, let me explain the current setup we have.
All our machine are currently attached to employer's Office 365 Azure Domain - as a result we don't have any way to apply GPOs and centrialize changes. Therefore if we want to make any changes we have to go around and make it on each machine. Currently I've written a small Powershell script that makes a couple of registry entries for us and that's been applied on each machine. However this means if we have to make a change to it, we need to replace that script with a different one on every box. So my line manager tasked me with writing a new script that would pull down a Powershell script from our file server, so we could update just that one and then have every machine pull that down and run it. Becuase we might not see these machines for some time, we agreed that the best method was getting this script to run as a scheduled task on log of any user.
The scheduled task is set to run as a local adminstrator account (have tried it using SYSTEM, but to no affect) and is triggered to run at any user logon; it's action is to start powershell.exe with the following arguement: -ExecutionPolicy Bypass c:\<folder>\<file>.ps1. Now I know this process works as I use the exact same method to run powershell scripts at the moment.
This script creates a temporary mapped drive and downloads a file from there; I know the script works, because if I run it from within Powershell ISE or just run it in explorer it runs and copies down the file, it just won't work when called by task scheduler.
When I initally created the script I had it map the drive using one of the DNS name of the fileserver it's pulling it from (it now uses both) and it used the local user's creadentials to map the drive, I've since modified the script to use both DNS names and to pull the user's credentials from the machine (just to be sure), but it still won't work as a scheduled task.
The task itself reports that it's run fine, so I'm guessing it's something to do with how Powershell interacts with Task Scheduler; is it somehow using the credentials for the task in Powershell?
I've attached a sanitized .txt version of the script for you to look at in case I've made an error there. Any advice/suggestions would be gratefully received.