简体   繁体   English

我无法让 powershell 在任务计划程序中运行

[英]I cant get powershell to run in task scheduler

I am trying to run the following Powershell script via the Task Scheduler but although it gives me a successful run (0x0), nothing happens.我正在尝试通过任务计划程序运行以下 Powershell 脚本,但尽管它让我成功运行 (0x0),但没有任何反应。 If I run the script manually from the same machine as a standard user the script executes without any issue.如果我以标准用户身份从同一台机器手动运行脚本,脚本将毫无问题地执行。

$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()

Just to clarify, I have tried different options in task scheduler such as running it under arguments like "-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File "C:\Temp\powershell.ps1" or SYSTEM and currently logged on user but nothing made a difference.澄清一下,我在任务调度程序中尝试了不同的选项,例如在 arguments 下运行它,例如“-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File”C:\Temp\powershell.ps1“或 SYSTEM 并且当前已登录用户但没有做任何事情一个区别。

My system is a domain joined Windows 10 with unrestricted access to the shared location (Everyone access)我的系统是一个加入 Windows 10 的域,可以不受限制地访问共享位置(所有人访问)

Any ideas?有任何想法吗?

I usually configure Task Scheduler to run a PowerShell script with the following settings:我通常将任务计划程序配置为使用以下设置运行 PowerShell 脚本:

New Action新动作

Action: "Start a program".动作:“启动程序”。

Program/script: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"程序/脚本:“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

Add arguments (optional): .\ ScriptName .ps1 - Arg1 Value1添加 arguments(可选):.\ ScriptName .ps1 - Arg1 Value1

Start in (optional): Path\to\Script\Directory开始于(可选): Path\to\Script\Directory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel 宏通过 powershell 运行,但在 Windows 任务计划程序运行时不运行 - Excel macros run through powershell but not when run by windows task scheduler 如何在任务调度程序中使用 VBA 正确运行 powershell 脚本? - How to properly run a powershell script using VBA in a task scheduler? Powershell 脚本未在任务计划程序上运行 - Powershell script not running on Task Scheduler Powershell 脚本适用于 ISE/控制台,但不适用于任务计划程序 - Powershell script works in ISE / Console but not Task Scheduler 如何创建任务计划程序任务或以其他方式运行 SSMS 查询以保存到文件位置? - How can I create a Task Scheduler task or otherwise run an SSMS query to save to a file location? 使用任务计划程序从 PowerShell 创建电子邮件(运行时错误 429) - Create email from PowerShell using Task Scheduler (Runtime Error 429) 通过任务计划程序运行时,Powershell脚本停止工作 - Powershell script stops working when ran through task scheduler Powershell Get-clipboard 功能在调度程序中不起作用 - Powershell Get-clipboard function not work in scheduler Excel任务计划程序。 我收到错误消息“ Microsoft Excel已停止工作” - Excel task scheduler. I get the error “Microsoft Excel has stopped working” 仅当 Windows 任务计划程序打开文件时才运行 Excel VBA - Run Excel VBA only if Windows task scheduler opened the file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM