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?