I have a short script that creates a directory on another server to archive some files. The script works fine from the command line but I want to use it in a schedule that runs at night under a service account. This nightly process does a bunch of stuff without fail but the ps script fails with access denied.
$today=get-date #$arcYear=$today.year $ArchiveRoot="\\bigfiles\k\WebAccessUpLoadArchive\2020Data\" $ArchiveSourceDir = "\\dataserver\d$\dailyTransfer\*.zip" $arcDat=$today.AddDays(-1) $now=$arcDat.tostring('yyyy_MM_dd') $arcdir=$archiveroot+$Now New-Item -Path $archiveroot -Name $now -ItemType 'Directory' 1 Answer
Task Security options
First of all in Security options of the task you have to set the task is run with admin privileges and with a admin account, and that the task is run whether user is logged on or not.
Setting Up Action
Then when adding an action to run a PowerShell script use the full path of powershell.exe. On my OS it is C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. And in arguments besides -File argument with the full path of the script you must add -NoProfile -Executionpolicy bypass arguments.
