我正在尝试直接在计划任务中运行以下 PowerShell 命令。
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'
它失败是因为计划任务似乎没有以管理权限运行。
任务配置如下:
- 运行用户是否登录
- 具有本地管理员权限的指定用户
- 以最高权限运行
- 操作 - 启动程序
- 程序 =
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'
文件夹的权限已更改为(经过身份验证的用户 = 完全控制)
如果我在同一个计划任务中运行以下命令,它将成功完成。
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'
有任何想法吗?