excel - 我无法让 powershell 在任务调度程序中运行
问题描述
我正在尝试通过任务计划程序运行以下 Powershell 脚本,但尽管它让我成功运行 (0x0),但没有任何反应。如果我从与标准用户相同的机器手动运行脚本,则脚本将毫无问题地执行。
$folderpath = "\\shared_path\excel.xls"
Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook
write-host $xlFixedFormat
$excel = New-Object -ComObject excel.application
$excel.visible = $false
$filetype ="*xls"
Get-ChildItem -Path $folderpath -Include $filetype -recurse |
ForEach-Object `
{
$path = ($_.fullname).substring(0, ($_.FullName).lastindexOf("."))
$workbook = $excel.workbooks.open($_.fullname)
$path += ".xlsx"
$excel.DisplayAlerts = $false;
$workbook.saveas($path, $xlFixedFormat)
$workbook.close()
}
$excel.Quit()
$excel = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
为了澄清起见,我在任务调度程序中尝试了不同的选项,例如在“-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File "C:\Temp\powershell.ps1" 或 SYSTEM 等参数下运行它,并且当前登录用户但什么也没做一个区别。
我的系统是加入 Windows 10 的域,可以不受限制地访问共享位置(所有人都可以访问)
有任何想法吗?
解决方案
我通常将任务计划程序配置为运行具有以下设置的 PowerShell 脚本:
新动作
行动:“启动程序”。
程序/脚本:“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”
添加参数(可选):.\ ScriptName .ps1 - Arg1 Value1
开始于(可选):Path\to\Script\Directory
推荐阅读
- java - 如何使用 Jsoup Android 的 HTML 解析在 android 中获取视频标签的 src?
- git - 关于如何创建存储库的建议(游戏改装)
- opengl - Vulkan 和 X11 像素图
- powershell - 如何使用 PowerShell 从字符串中读取特定变量?
- reactjs - MERN 部署到 heroku - 应用程序功能不起作用
- mysql - 防止 MySQL 更新多于一行
- r - 按值过滤列表列表
- apache-spark - java.lang.NoClassDefFoundError 上的错误:org/apache/spark/sql/SQLContext
- python - 将相似的嵌套字典的值组合成一个新的嵌套字典
- docker - 如何决定在 Kubernetes 中我需要多少个服务实例?