0
votes

I am trying to run the following PowerShell command directly in a Scheduled Task.

Powershell.exe -command Get-ChildItem -Path 'C:\Program Files (x86)\CA\ARCserve Backup\Reports' -Force | Where-Object {($_.Name -like 'AB*.xml') -and ($_.LastWriteTime -lt (get-date).AddDays(-7))} | Move-Item -Destination 'C:\Program Files(x86)\CA\ARCserve Backup\Reports\OldReports'

It fails because the scheduled task does not appear to be running with administrative privileges.

The task is configured as follows:

  • Run whether user is logged on or not
  • Specified user with local admin rights
  • Run with highest privileges
  • Action - Start a program
  • Program = powershell.exe
  • Parameters = -command Get-ChildItem -Path 'C:\Program Files (x86)\CA\ARCserve Backup\Reports' -Force | Where-Object {($_.Name -like 'AB*.xml') -and ($_.LastWriteTime -lt (get-date).AddDays(-7))} | Move-Item -Destination 'C:\Program Files(x86)\CA\ARCserve Backup\Reports\OldReports'

Permissions on folder have been changed to (authenticated users = full control)

If I run the command below in the same scheduled task, it completes successfully.

powershell.exe -command Get-ChildItem -Path 'C:\Reports' -Force | Where-Object {($_.Name -like 'AB*.xml') -and ($_.LastWriteTime -lt (get-date).AddDays(-7))} | Move-Item -Destination 'C:\Reports\OldReports'

Any ideas?

1

1 Answers

0
votes

Maybe the execution policy is too restricted for this account. try to set the executionpolicy by adding -executionpolicy unrestricted in the parameters. If that failed, it would help to see the log of the scheduler.