簡體   English   中英

我無法讓 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()

澄清一下,我在任務調度程序中嘗試了不同的選項,例如在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM