windows - 计划的 Powershell 任务,卡在运行中

标签 windows powershell scheduled-tasks

我在计划任务中运行 powershell 脚本时遇到问题。它卡在运行中,即使成绩单已注销最后一行“完成!”而且它看起来也完全按照我的意愿完成了。我错过了什么?

在 Windows 中从 Run 运行它时,它似乎也很好:powershell -file "D:\_temp\copy_bat\copy_one_reprint_folder.ps1"

任务计划程序中的设置是:

  • 以完全权限运行
  • 无论用户是否登录都运行
  • 行动,启动程序powershell.exe
    • -file "D:\_temp\copy_bat\copy_one_reprint_folder.ps1"

Stuck in Running History in TS

如果需要请看下面的代码。

# PowerShell RePRINT copy first folder, sorted on lastModified
function timestamp
{
    $ts = Get-Date -format s
    return $ts
}

$fromDirectory = "D:\_temp\copy_bat"
$toDirectory = "D:\_temp\in_dummy"
$extractGUIDdir = ""
$docTypeDir = ""

# Logging
#########
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $fromDirectory\copy_one_reprint_folder.log.txt -append
###########


Write-Host ""
Write-Host (timestamp) "Copy RePRINT extract started"
Write-Host (timestamp) "============================"

Get-ChildItem -path $fromDirectory | ?{ $_.PSIsContainer } | Sort-Object CreationTime | `
    Where-Object {$_.name -ne "_copied"} | `
    Select-Object -first 1 | `
        Foreach-Object{
            Write-Host (timestamp) $_.name
            $extractGUIDdir = $_.FullName
            Get-ChildItem -path $extractGUIDdir |  ?{ $_.PSIsContainer } | Where-Object {$_.Name -match "Purchase Order \(-999999997\)" -or $_.Name -match "Logistics documents \(-1000000000\)" -or $_.Name -match "Specifications \(-999999998\)"} | `
                Foreach-Object{
                    Write-Host (timestamp) "  " $_.Name
                }
            Write-Host ""

            Write-Host "These folders (document types), were also found but will not be included"
            Get-ChildItem -path $extractGUIDdir -Exclude "Logistics documents (-1000000000)", "Purchase Order (-999999997)", "Specifications (-999999998)" | ?{ $_.PSIsContainer } | `
                Foreach-Object{
                    Write-Host (timestamp) " - " $_.name
                }
            Write-Host ""

            Get-ChildItem -path $extractGUIDdir | ?{ $_.PSIsContainer } | Where-Object {$_.Name -match "Purchase Order \(-999999997\)" -or $_.Name -match "Logistics documents \(-1000000000\)" -or $_.Name -match "Specifications \(-999999998\)"} | `
                Foreach-Object{
                        $temp_name = $_.FullName
                        Write-Host (timestamp) "copying files from " $_.FullName
                        Write-Host (timestamp) "                    to "  $toDirectory
                        #Copy-Item ($_.FullName)\*.* $toDirectory
                        Write-Host (timestamp) " copying meta-files..."
                        Copy-Item $temp_name\*.meta $toDirectory -Filter *.meta
                        Write-Host (timestamp) " copying pdf-files..."
                        Copy-Item $temp_name\*.pdf $toDirectory -Filter *.pdf
                        if(Test-Path $temp_name\*.* -Exclude *.meta, *.pdf)
                        {
                            Write-Host (timestamp) " WARNING/ERROR not all documents have been moved. Only PDFs was moved!"
                            Write-Host (timestamp) " Check folder for other document-types."
                        }
                }
                Move-Item $extractGUIDdir $fromDirectory\_copied
        }

Write-Host (timestamp) " DONE!"

# Stop logging
Stop-Transcript

最佳答案

解决了。

有效,愚蠢的我没有在任务调度程序中按 F5(update) 来更新 gui 中任务的状态。

实际上我很确定我这样做了,但显然不是。

关于windows - 计划的 Powershell 任务,卡在运行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26296187/

相关文章:

c++ - 通过从 C/C++ 调用 Windows API 函数来生成独立的汇编子例程

c++ - 如何使用 PlaySound() 或任何基本函数/方法同时在 C++ 中播放超过 1 个 .wav 声音?

java - Quartz Scheduler (cron) 能否在同一执行时间调度多个作业?

c# - 自定义任务计划程序按日期时间启动任务

java - 具有时间延迟的递归函数调用

php - 在 Windows 上执行 Git 钩子(Hook)

Java:在机器人类中按 ENTER 键不起作用

powershell - 如何将数组参数传递给 powershell -file?

powershell - 在 PowerShell 中脚本回显当前命令

powershell - 为什么使用 Chocolatey/PowerShell DSC 时 OpenSSL 安装会挂起?