[英]Another Task Scheduler not executing PowerShell
我有一個簡單的PowerShell腳本,它只能創建一個文件。 針對更大的PowerShell腳本進行測試。
在Windows Server 2012 R2上運行-64位
它以管理員帳戶運行。
運行用戶是否已登錄
以最高特權運行
行動:程序/腳本:Powershell.exe(我已經嘗試過這種方法和完整路徑)
添加參數:-NoProfile -executionpolicy remotesigned-文件C:\\ Scripts \\ test.ps1
Get-executionPolicy:RemoteSigned
已將“管理員”添加到:Set-PSSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI
“管理員”具有“以批處理身份登錄”權限“管理員”在Admins組中
用於測試的PowerShell腳本:
$text = "Hello World"
$text | Set-Content TestMyFile.txt
$text | Out-File TestMyFile.txt
$text > TestMyFile.txt
# This is to write into a file or append to the text file created:
$text | Add-Content TestMyFile.txt
$text | Out-File TestMyFile.txt -Append
$text >> TestMyFile.txt
沒什么,只是嘗試確保Task Scheduler將執行PowerShell腳本。
那我想念什么?
在輸出代碼中使用完整路徑,並且對於將來在Task Scheduler中運行腳本遇到的任何問題,應首先獲取日志記錄和try/catch
塊,以查看腳本正在生成什么錯誤/輸出,然后再尋求進一步的幫助。 這樣做將幫助您更快地找到答案並同時更快地學習。
提示:始終僅在Task Scheduler的“要運行的程序”方面為程序命名,因為Task Scheduler使用其自己的包裝器來執行操作,並且在極少數情況下,如果將整個執行行放在其中,它可能會產生不良結果。這個領域。 始終將參數放在參數字段中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.