2013-06-03 17 views
5

Trochę prostego pytania, ale jak wybrać konkretną kolumnę w poniższym kodzie?wyświetla tylko jedną kolumnę w wyniku?

Chcę tylko pokazać kolumnę TIME i nic więcej. Staram i umieścić w FORMAT_TABLE czas, ale to po prostu zapełnia z czasem wiele razy bez faktycznie wskazujące czas ..

$server_event = Get-Content -Path "c:\Temp\Servers.txt" 

foreach($servers in $server_event) 
{ 

$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select -First 1 

$event 

} 

WYNIK: Chcę tylko pokazać kolumnie Czas

Index Time   EntryType Source     InstanceID Message                      
    ----- ----   --------- ------     ---------- -------                      
    78858 Jun 01 07:19 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    46221 Jun 01 07:20 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    214480 Jun 01 07:46 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    461238 Jun 01 07:18 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    70889 Jun 01 07:17 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    52397 Jun 01 07:19 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.      
    42219 Jun 01 07:40 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Uniprocessor Free.  

Odpowiedz

6

try:

$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select TimeGenerated -First 1 
+1

ahhh ........ TimeGenerated! Właśnie dlatego mnie to dezorientowało! jak znaleźć dokładną nazwę kolumn C.B.? – lara400

+0

Zamiast tego należy użyć 'Get-WinEvent'. 'Get-EventLog' jest dla [kompatybilności wstecznej] (http://technet.microsoft.com/en-us/library/hh849682.aspx) (patrz sekcja Uwagi). Aha, i to jest TimeCreated, a nie TimeGenerated. – vonPryz

+3

w ten sposób: '(Get-EventLog -logname system) [0] | fl * 'zwraca listę wszystkich właściwości dla pojedynczego zdarzenia. Znajdziesz także 'timewritten', ale IIRC to domyślny format PowerShell' 'Timegenerated' –

2

Możesz zobaczyć, jak nazwy są ponownie sformatowane, patrząc w pliku o nazwie DotNetTypes.format.ps1xml, który znajduje się w katalogu $pshome.

Jeśli szukasz System.Diagnostics.EventLogEntry zobaczysz następujące dane, które formatuje TimeGenerated jak czas i wyświetlacza jako: {0} {0 MMM: dd} {0: HH}: {0: mm}:

<View> 
    <Name>System.Diagnostics.EventLogEntry</Name> 
    <ViewSelectedBy> 
     <TypeName>System.Diagnostics.EventLogEntry</TypeName> 
    </ViewSelectedBy> 

    <TableControl> 
     <TableHeaders> 
      <TableColumnHeader> 
       <Label>Index</Label> 
       <Alignment>Right</Alignment> 
       <Width>8</Width> 
      </TableColumnHeader> 
      <TableColumnHeader> 
       <Label>Time</Label> 
       <Width>13</Width> 
      </TableColumnHeader> 
      <TableColumnHeader> 
       <Label>EntryType</Label> 
       <Width>11</Width> 
      </TableColumnHeader> 
      <TableColumnHeader> 
       <Label>Source</Label> 
       <Width>20</Width> 
      </TableColumnHeader> 
      <TableColumnHeader> 
       <Label>InstanceID</Label> 
       <Alignment>Right</Alignment> 
       <Width>12</Width> 
      </TableColumnHeader> 
      <TableColumnHeader> 
       <Label>Message</Label> 
      </TableColumnHeader> 
     </TableHeaders> 
     <TableRowEntries> 
      <TableRowEntry> 
       <TableColumnItems> 
        <TableColumnItem> 
         <PropertyName>Index</PropertyName> 
        </TableColumnItem> 
        <TableColumnItem> 
         <PropertyName>TimeGenerated</PropertyName> 
         <FormatString>{0:MMM} {0:dd} {0:HH}:{0:mm}</FormatString> 
        </TableColumnItem> 
        <TableColumnItem> 
         <ScriptBlock>$_.EntryType</ScriptBlock> 
        </TableColumnItem> 
        <TableColumnItem> 
         <PropertyName>Source</PropertyName> 
        </TableColumnItem> 
        <TableColumnItem> 
         <PropertyName>InstanceID</PropertyName> 
        </TableColumnItem> 
        <TableColumnItem> 
         <PropertyName>Message</PropertyName> 
        </TableColumnItem> 
       </TableColumnItems> 
      </TableRowEntry> 
     </TableRowEntries> 
    </TableControl> 
</View> 

Więc można uzyskać tylko Kolumna razem używając TimeGenerated następująco:

Get-EventLog -LogName System | select TimeGenerated 
Powiązane problemy