私は既にここの回答を検索しましたが、私の言うことにはっきりと答えるものは見つかりませんでした。私は、テキストファイルで定義されているいくつかのサーバーに手を差し伸べ、EventLogから詳細を報告するスクリプトを用意しています。また、ファイルに書き出し、結果のファイルを添付ファイルとして電子メールで送信し、コマンド処理に要した時間もわかります。全体的なパフォーマンスを監視し、時間の経過とともに変更があるかどうかを確認することができます。その部分はうまく動作します。Powershellスクリプトは手動で実行すると異なる結果を示します
Write-Output ($Start = Get-Date) | Out-File -Append F:\PowerShell\UnExpectedShutdowns.txt
$Computers = Get-Content -Path F:\PowerShell\servers.txt
Get-EventLog -logname System -ComputerName $Computers | ? {$_.TimeWritten -gt $lasttime -and $_.EventID -eq "6008"} | Format-Table -Wrap -Property MachineName, Index, TimeGenerated, EntryType, Source, InstanceID, Message -AutoSize | Out-File -Append -Force F:\PowerShell\UnExpectedShutdowns.txt
Write-Output (($Stop = Get-Date) - $Start).TotalSeconds | Out-File -Append F:\PowerShell\UnExpectedShutdowns.txt
Send-MailMessage -From [email protected] -Subject "Daily Check for Server Shutdowns" -To [email protected] -Attachments F:\PowerShell\UnExpectedShutdowns.txt -Body "<p style=""font-family: Verdana, Geneva, sans-serif; font-size: 12px;"">Please review the attached document for new unexpected server shutdowns. </p><p> </p><p style=""font-family: Verdana, Geneva, sans-serif; font-size: 12px;"">The original file is located on <a href=""file:///\\SERVER\F$\Powershell\UnExpectedShutdowns.txt"">\\SERVER\F$\Powershell\UnExpectedShutdowns.txt</a></p><p style=""font-family: Verdana, Geneva, sans-serif; font-size: 12px;"">It should be pared down from time to time to maintain its size</p>" -BodyAsHtml -Priority Normal -SmtpServer smtp.dept.domain.com
これをスケジュール済みのタスクとして追加しました。私がタスクスケジューラの外で手動で実行すると、私が期待した結果が得られます。私はそれがスケジュールどおりに実行してみましょうとき
MachineName Index TimeGenerated EntryType Source InstanceId Message
----------- ----- ------------- --------- ------ ---------- -------
SERVERNAME9999.fqdn 123456 3/10/2016 11:11:46 AM Error EventLog 1234567890 The previous system shutdown at 11:08:17 AM on 3/10/2016 was unexpected.
しかし、私はスケジュールされたタスクとして結果マイナス最後の2列(インスタンスID &メッセージ)
MachineName Index TimeGenerated EntryType Source
----------- ----- ------------- --------- ------
SERVERNAME9999.fqdn 123456 3/10/2016 11:11:46 AM Error EventLo
g
を取得し、私はアカウントを使用して、それを実行していますすべてのサーバーの管理者グループに属しており、「最高の権限で実行」オプションが選択されています。最後の2列が表示されないのはなぜですか?
使用してみてください 'の代わりSELECT''あなたが実際に同じパラメータが、と同じことを実行している場合フォーマット-Table'奇妙なショット – nkasco
は非直列化データとは何かを持っている必要があり価値があります。それらのプロパティは、タスクとして実行されているときには設定されていない可能性があります。 – Matt