我无法在任务计划程序中将 powershell 设置为 运行

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

澄清一下,我在任务调度程序中尝试了不同的选项,例如 运行在“-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File”C:\Temp\powershell.ps1" 或 SYSTEM 和当前登录的用户,但没有任何区别。

我的系统加入了一个域Windows 10,可以不受限制地访问共享位置(所有人访问)

有什么想法吗?

我通常将 Task Scheduler 配置为 运行 具有以下设置的 PowerShell 脚本:

新动作

操作:“启动程序”。

Program/script: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

添加参数(可选):.\ScriptName.ps1 -Arg1 Value1

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