【发布时间】:2017-11-08 05:54:02
【问题描述】:
我可以在任务计划程序内外运行脚本。但是计划任务在触发时不会自动运行脚本。我尝试通过更改来配置本地安全策略,用户帐户控制:Built-i 管理员帐户的管理员批准模式(未定义) - 用户帐户控制:在管理员批准模式下运行所有管理员(已禁用) - 用户帐户控制:行为管理员批准模式下的管理员提升提示(不提示提升)。这没有用。任何帮助都会很棒。谢谢。
程序/脚本:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
添加参数:-NoProfile -ExecutionPolicy Bypass -File C:\Users\Andersen\Desktop\moveFiles.ps1
Try
{
$Time = Get-Date
if(Test-Path C:\Users\Andersen\Desktop\src) {
"Source exists."
} else {
Write-Output "This script made a read attempt at [$Time]. Source (C:\Users\Andersen\Desktop\src) cannot be found." | out-file C:\Users\Andersen\Desktop\KofaxScriptErrorLog.txt -Append
Exit
}
$IDsrc = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\ID - Sub Invoice").Count
$Jsrc = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\J - Sub Invoice").Count
$ORsrc = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\OR - Sub Invoice").Count
$OR2 = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\OR2 - Sub Invoice").Count
$SCsrc = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\SC Invoice").Count
$WAsrc = (Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\WA - Sub Invoice").Count
# move Kofax ID files to ID folder in Egnyte
If ($IDsrc -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\ID - Sub Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\ID - Sub Invoice" -Force -ErrorAction Stop
}
# move Kofax J files to J folder in Egnyte
If ($Jsrc -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\J - Sub Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\J - Sub Invoice" -Force -ErrorAction Stop
}
# move Kofax OR files to OR folder in Egnyte
If ($ORsrc -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\OR - Sub Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\OR - Sub Invoice" -Force -ErrorAction Stop
}
# move Kofax OR2 files to OR2 folder in Egnyte
If ($OR2src -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\OR2 - Sub Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\OR2 - Sub Invoice" -Force -ErrorAction Stop
}
# move Kofax SC(multi) files to SC(multi) folder in Egnyte
If ($SCsrc -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\SC Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\SC Invoice" -Force -ErrorAction Stop
}
# move Kofax WA files to WA folder in Egnyte
If ($WAsrc -ne 0){
Get-ChildItem -Path "C:\Users\Andersen\Desktop\src\WA - Sub Invoice" -Recurse -ErrorAction Stop |
Move-Item -Destination "C:\Users\Andersen\Desktop\Current Imaging\WA - Sub Invoice" -Force -ErrorAction Stop
}
}
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
"The script to move files from the Kofax server to Egynte made a run attempt at $Time. Error Details: $ErrorMessage $FailedItem" | out-file C:\Users\Andersen\Desktop\KofaxScriptErrorLog.txt -Append
Break
}
Finally
{
"This script made a complete read attempt at $Time" | out-file C:\Users\Andersen\Desktop\KofaxScriptLog.txt -Append
}
【问题讨论】:
-
批量登录的成员?
-
你试过
-ExecutionPolicy Unrestricted吗?此外,您可以尝试在“程序/脚本:”中使用批处理来启动您的 Powershell 脚本,而不是直接设置您的 ps1 文件以查看行为是否相同? -
@notjustme 是的,我将自己添加到“作为批处理作业登录”
-
任务调度器是否说明了上次运行结果?
标签: powershell scheduled-tasks