2013-06-03 13 views
5

Bit di una domanda semplice ma come faccio a selezionare una colonna specifica nel codice seguente?mostra solo una colonna nel risultato?

Voglio solo mostrare la colonna TIME e nient'altro. Cerco di mettere in tempo FORMAT_TABLE ma semplicemente popola con il tempo più volte senza in realtà che mostra il tempo ..

$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 

} 

RISULTATO: voglio solo Mostra la colonna TEMPO

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.  

risposta

6

prova:

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

ahhh ........ TimeGenerated! Ecco perché mi stava confondendo! come si trova il nome esatto delle colonne C.B.? – lara400

+0

Inoltre, utilizzare 'Get-WinEvent'. Il 'Get-EventLog' è per [retrocompatibilità] (http://technet.microsoft.com/en-us/library/hh849682.aspx) (vedere la sezione Note). Oh, e quindi è TimeCreated, non TimeGenerated. – vonPryz

+3

in questo modo: '(Get-EventLog -logname system) [0] | fl * 'restituisce un elenco di tutte le proprietà per un singolo registro eventi. Si trova anche 'timewritten', ma IIRC quello che si vede per default nel formato PowerShell' Timegenerated' –

2

È possibile vedere come i nomi vengono riformattati cercando nel file denominato DotNetTypes.format.ps1xml questo si trova nella directory $pshome.

Se si cerca System.Diagnostics.EventLogEntry vedrete quanto segue, che formatta TimeGenerated come il tempo e il display come {0: MMM} {0: 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> 

Così si può ottenere solo la colonna Ora utilizzando TimeGenerated come segue:

Get-EventLog -LogName System | select TimeGenerated 
Problemi correlati