Bit of a simple question but how do I select a specific column in the below code?
I only want to show TIME column and nothing else. I try and put in FORMAT_TABLE TIME but it just populates with TIME multiple times without actually showing the time..
$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
}
RESULT: I ONLY WANT TO SHOW THE TIME COLUMN
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.
try:
$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select TimeGenerated -First 1
You can see how the names get re-formatted by looking in the file named DotNetTypes.format.ps1xml
this is located in the $pshome
directory.
If you search for System.Diagnostics.EventLogEntry
you'll see the following, which formats TimeGenerated as Time and the display as {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>
So you can get just the Time Column using TimeGenerated as follows:
Get-EventLog -LogName System | select TimeGenerated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With