Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 计划的Powershell任务,无法运行_Windows_Powershell_Scheduled Tasks - Fatal编程技术网

Windows 计划的Powershell任务,无法运行

Windows 计划的Powershell任务,无法运行,windows,powershell,scheduled-tasks,Windows,Powershell,Scheduled Tasks,在计划任务中运行powershell脚本时出现问题。它被困在运行中,即使成绩单已经注销了最后一行“完成!”,而且它看起来也完全完成了我想要它做的。我错过了什么 在Windows中从Run运行时,它看起来也很好:powershell-file“D:\\u temp\copy\u bat\copy\u one\u reprint\u folder.ps1” 任务计划程序中的内容包括: 私奔 Run weither用户是否已登录 操作,启动程序powershell.exe -文件“D:\\u te

在计划任务中运行powershell脚本时出现问题。它被困在运行中,即使成绩单已经注销了最后一行“完成!”,而且它看起来也完全完成了我想要它做的。我错过了什么

在Windows中从
Run
运行时,它看起来也很好:
powershell-file“D:\\u temp\copy\u bat\copy\u one\u reprint\u folder.ps1”

任务计划程序中的内容包括:

  • 私奔
  • Run weither用户是否已登录
  • 操作,启动程序
    powershell.exe
    • -文件“D:\\u temp\copy\u bat\copy\u one\u reprint\u folder.ps1”

如果需要,请参阅下面的代码

# 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
(更新)来更新gui中任务的状态


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

最愚蠢的事情是UI只是部分事件驱动的,所以我们可以自动看到它何时启动,何时结束。我在这个问题上浪费了一个小时。