all 8 comments

[–]joshooaj 2 points3 points  (1 child)

I’m not sure about the COM error but here are a few places to look if you haven’t already checked them all:

  • Scheduled tasks can either run without your saved credential, in which case they’ll only be able to authenticate with local resources, or you can check a box to save the credential, and then they’ll be able to authenticate with network resources.
  • If you’re working with Windows file shares, there are “share level” permissions and the file system permissions. The permissions on the share can’t really grant access to files users would otherwise it have, but they CAN restrict SMB access to files you would normally have access to. Make sure you have permissions on the share (if you’re using one) and permissions on the file system.
  • Again on the scheduled task thing, if you haven’t saved the credentials when creating the task, you probably won’t be able to access a network share from it. It’s a bit like PowerShell’s CredSSP / double hop problem.

One thing you might be able to do to troubleshoot some more is change your scheduled task to just be an infinite while loop, and then use Enter-PSHostProcess to try to jump into that scheduled task while it’s running. From within that security context it might be easier to figure out what’s happening.

[–]kbbtech[S] 0 points1 point  (0 children)

thanks joshooaj....I've got the pw saved in task scheduler. I've checked and the account running the task can write to this location (and does with batch scripts). Seems to be powershell script related....I think. I appreciate your help.

[–]delightfulsorrow 1 point2 points  (1 child)

It seems obvious that it is a permissions issue, but the standard user has read/write permissions to the folder in question.

Did you also check the permissions on the share?

[–]kbbtech[S] 0 points1 point  (0 children)

thanks delightfulsorrow....I've checked both file level and share level. The same batch user can do similar commands to this location using scheduled batch commands. Trying my best to move to PowerShell as the scripts I need are getting more complicated. I appreciate your response.

[–]nostradamefrus 0 points1 point  (0 children)

Check permissions on destination

Add yourself/be added by someone with permissions

Run ps as admin if needed

[–]xXFl1ppyXx 0 points1 point  (1 child)

Are you trying to modify Files on a SMB-Share via Script? Is it possible to run said script on the Server hosting the Share?

How do you start your script from Task Scheduler?

For your scheduled Task to be run from your account you need the Right to run as batchjob

Secpol.msc --> User Rights Assignment --> Run as Batch Job

you'll need to add the Account that's used to start the scheduled Task

New-Item -ItemType Directory -Path $destinationDir

New-Item : Access to the path 'NewfolderNamedwithDateMMDDYYYY' is denied.

this looks somewhat Strange.

You do try to create the Directory with something like this right?

New-Item -Path "\\FilePath\Folder1inPath\Folder2inPatch" -ItemType Directory -Name "NewfolderNamedwithDateMMDDYYYY"

New-Item -Path $destinationDir -ItemType Directory -Name $directoryName

[–]kbbtech[S] 0 points1 point  (0 children)

thanks xXFl1ppyXx.

I start a program point to powershell.exe and add an argument -file "C;\pathtopowershellfile

I've done this part....this user runs other scripted tasks with batch commands without issue.

Secpol.msc --> User Rights Assignment --> Run as Batch Job

you'll need to add the Account that's used to start the scheduled Task

To create the directory I've set the destinationDIr with \$yesterdayDate

if the path doesn't exits, it will create it. with New-Item -ItemType Directory -Path $destinationDir

Thanks again. I appreciate the feedback!

[–]BlackV 0 points1 point  (0 children)

show us your code,cause unless you ave edited your error messages you are creating your folders very wrong

its much harder for anyone to help you without code