0
votes

I've got a powershell script to archive log files. The script is intended to be run daily from a scheduled task as a specified user 'LogArchiver'.

The script uses the aws-cli to copy the file to S3 and needs sufficient credentials to access the bucket which are stored in the user directory C:\Users\LogArchiver\.aws as recommended in the aws docs.

When I run the script from a powershell terminal running as the user it recognises the credentials and successfully copies files to S3. But when it is run from the scheduled task it doesn't recognise the aws credentials and writing the Transcript to file shows the message:

Unable to locate credentials. You can configure credentials by running "aws configure".

Anyone know why this is and any fixes to it? I've read in another post about scheduled tasks doing funny things to environment variables but not sure if that would cause the problems i'm having.

1
Is the scheduled task running as the user that has the credentials file? - James C.
Yes, it is setup to run as the user. It is also confirmed in the Transcript file as running as that user. ********************** Windows PowerShell transcript start Start time: 20161124184413 Username: LogArchiver RunAs User: LogArchiver ... - chestercodes

1 Answers

0
votes

Turns out that it was a bug in server 2012 and is fixed by this patch https://support.microsoft.com/en-gb/kb/3133689

The 'fix' for me was to change the USERPROFILE environment variable at the top of the script with

$env:USERPROFILE = "C:\Users\LogArchiver"

Not elegent, but works.