2016-02-16 34 views
0

這是我的工作,生成的時間字段沒有出現。Powershell格式表給我的問題

param ($redflags) 
$count = 0 
$n = get-eventlog $redflags -entrytype error, warning| where-object { $_.EntryType -eq 'Error' -or $_.EntryType -eq 'warning' } 
$f = $n | foreach {$count++} | format-table @{Label="TimeGenerated"; Expression={$_.Timegenerated}} -autosize 
$n 
Write-host "The number of redflags is $count" 
+0

您收到的錯誤是什麼?考慮在你的問題中增加更多細節,因爲它可以幫助其他人提出答案。 – Joyson

+0

你不用管任何東西到'Format-Table',所以它不會返回任何東西。 – PetSerAl

回答

0

正如@PetSerAl所示,您沒有將任何東西輸送到Format-Table。我想程序更改爲以下:

param ($redflags) 
$count = 0 
$n = get-eventlog $redflags -entrytype error, warning 
$n | format-table @{Label="TimeGenerated"; Expression={$_.Timegenerated}} -autosize 
$n | foreach { $count++ } 
$n 
Write-Host "The number of redflags is $count" 
  1. 在你原來的$ N,該位置對象是多餘的。 -EntryType已經捕獲所有錯誤和警告。
  2. 不需要使用$ f。