Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

New-Item : Access to the path '2020_10_19' is denied

Writer Mia Lopez

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.

enter image description here

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.

enter image description here

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy