PowerShell 脚本手动运行而不是在任务计划程序中运行

问题描述 投票:0回答:1

Action Tab

.bat 文件在手动调用时运行得很好,但在任务调度程序中它会呕吐。输出文件显示无法访问 Excel 文件。

  • 我有多个其他使用此文件路径运行的 powershell 和 .bat 文件脚本。

  • 确保没有其他人打开该文件。

在这一点上迷失了。

.bat 文件

@echo off

powershell.exe -ExecutionPolicy Bypass -File "%~dp0\WhiteBoard_Update.ps1" > "%~dp0\output_update.txt" 2>&1
powershell.exe -ExecutionPolicy Bypass -File "%~dp0\WhiteBoard_Html.ps1" > "%~dp0\output_html.txt" 2>&1

WhiteBoard_Update.ps1 的输出文件

Microsoft Excel cannot access the file '\\file\network\Production\Programs\WhiteBoard.xlsx'. There are several 
possible reasons:
 The file name or path does not exist.
 The file is being used by another program.
 The workbook you are trying to save has the same name as a currently open workbook.
At \\file\network\Production\Programs\WhiteBoard_Update.ps1:8 char:1
+ $workbook = $excel.Workbooks.Open($wbExcelPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
excel powershell batch-file windows-task-scheduler
1个回答
0
投票

当您的脚本尝试打开 Excel 文件时,我会冒险猜测该文件已经打开。通过文件服务器上的计算机管理检查打开的文件是否打开。另外,不要忘记在脚本末尾关闭 excel 文件。

© www.soinside.com 2019 - 2024. All rights reserved.