[英]Excel macros run through powershell but not when run by windows task scheduler
[英]I cant get powershell to run in task scheduler
我正在尝试通过任务计划程序运行以下 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()
澄清一下,我在任务调度程序中尝试了不同的选项,例如在 arguments 下运行它,例如“-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File”C:\Temp\powershell.ps1“或 SYSTEM 并且当前已登录用户但没有做任何事情一个区别。
我的系统是一个加入 Windows 10 的域,可以不受限制地访问共享位置(所有人访问)
有任何想法吗?
我通常将任务计划程序配置为使用以下设置运行 PowerShell 脚本:
新动作
动作:“启动程序”。
程序/脚本:“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”
添加 arguments(可选):.\ ScriptName .ps1 - Arg1 Value1
开始于(可选): Path\to\Script\Directory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.