Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unable to display time in the powershell script parsing Event Log ?

Posted on 2016-09-13
4
Medium Priority
?
110 Views
Last Modified: 2016-09-13
Hi People,

Can anyone here please help as to why the script below can display the rest of the column but not the time column ?

Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))" | Get-EventLog -LogName Security 4720,4722,4725 |
 Select-Object EventId, Time, @{ 
   n='AccountName';
   e={ ($_.message -replace '\n', ' ') -replace '.*?account name:\t+([^\s]+).*', '$1' } 
 }, @{
   n='TargetAccount';
   e={ ($_.message -replace '\n', ' ') -replace '.*account name:\t+([^\s]+).*', '$1' } 
 } 

Open in new window


Am I missing anything here ?
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 41797345
The events returned don't have a property "Time". Try "TimeGenerated" instead.
1
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 41797360
OBDA,

Thanks for the clarification,

somehow the pipe does not work ?

Get-EventLog : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41797366
Sorry, didn't verify that part.
The ComputerName argument doesn't accept pipeline input, so you'll need a ForEach-Object:
Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))" |
	ForEach-Object {
		"Processing $($_.DNSHostName) ..." | Write-Host
		Get-EventLog -ComputerName $_.DNSHostName -LogName Security 4720, 4722, 4725 |
		Select-Object -Property `
			EventId,
			TimeGenerated,
			@{n='AccountName'; e={ ($_.message -replace '\n', ' ') -replace '.*?account name:\t+([^\s]+).*', '$1' }},
			@{n='TargetAccount'; e={ ($_.message -replace '\n', ' ') -replace '.*account name:\t+([^\s]+).*', '$1' }}
	}

Open in new window

1
 
LVL 8

Author Closing Comment

by:Senior IT System Engineer
ID: 41797375
You are awesome man !
Thanks
0

Featured Post

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question