Powershell 腳本在任務排程程式中手動執行,但不會作為排程任務執行

Powershell 腳本在任務排程程式中手動執行,但不會作為排程任務執行

我在虛擬機器上安裝了 PS 腳本。我的虛擬機器已連接到一個網域帳戶,我提供了一個服務帳戶。現在我的腳本正在手動運行。但是當我等待設定腳本的時間時它不起作用。我使用的是 Windows Server 2016。

電源外殼腳本

$path = "C:\Users\svaccount\Desktop\STAT1\"
$fileName = "STAT1_"
$date = Get-Date -Format MMddyyyhhmmss 
$file = $path + $filename +
$date + ".jpeg"  
Add-Type -AssemblyName System.Windows.Forms 
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information 
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen 
$Width = $Screen.Width 
$Height = $Screen.Height 
$Left = $Screen.Left 
$Top = $Screen.Top
# Create bitmap using the top-left and bottom-right bounds 
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object 
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen 
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file 
$bitmap.Save($File)

我在任務中的配置。

常規選項卡
-安全選項
   .帳戶使用者:(服務帳戶)
   .我選擇“僅在用戶登入時運行”
   .選擇以最高權限運行
   .configure for:Windows Server 2016

觸發選項卡
開始任務:按計劃進行
設定:每日、每 1 天重複一次
進階設定:選擇 重複任務間隔:5 分鐘,持續 1 年
選擇啟用

操作選項卡
動作:啟動一個程式
設定:
   .程式/腳本:powershell.exe
   .add 參數(可選):-windowstyle 隱藏“C:\POGI.ps1”

條件選項卡
   .選擇喚醒電腦來執行此任務

設定選項卡
    .選定允許任務按需運行

我找到一行來調試我的腳本:我不知道這是否有幫助

**********************
Windows PowerShell transcript start
Start time: 20181129151208
Username: OSISOFT\svaccount
RunAs User: OSISOFT\svaccount
Machine: PI-WBS (Microsoft Windows NT 10.0.14393.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 19732
PSVersion: 5.1.14393.206
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.206
BuildVersion: 10.0.14393.206
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is c:\temp\debug.log
**********************
Windows PowerShell transcript end
End time: 20181129151209
**********************

感謝您對此的幫助

謝謝!

相關內容