Powershell スクリプトはタスク スケジューラで手動で実行されますが、スケジュール タスクとしては実行されません。

Powershell スクリプトはタスク スケジューラで手動で実行されますが、スケジュール タスクとしては実行されません。

仮想マシンに PS スクリプトをインストールしました。VM はドメイン アカウントに接続されており、サービス アカウントが 1 つ提供されています。現在、スクリプトは手動で実行されています。ただし、スクリプトを設定した時間を待っている間は、スクリプトが機能しません。Windows Server 2016 を使用しています。

Power Shell スクリプト

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

タスク内の私の構成。

一般タブ
-セキュリティオプション
   .account ユーザー: (サービス アカウント)
   ユーザーがログオンしているときのみ実行を選択します
   最高権限で実行を選択しました
   .configure 対象: Windows Server 2016

トリガータブ
タスクの開始: スケジュールに従って
設定: 毎日、1 日ごとに繰り返す
詳細設定: 選択済み タスクを 5 分ごとに繰り返し、1 日の期間実行
ENABLEが選択されています

アクションタブ
アクション: プログラムを起動する
設定:
   プログラム/スクリプト: powershell.exe
   .add 引数(オプション): -windowstyle hidden "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
**********************

ご協力ありがとうございます

ありがとう!

関連情報