Solved

Modifying PowerShell script to get the Security logs for user Domain\Administrator from all AD domain controllers ?

Posted on 2016-09-11
8
85 Views
Last Modified: 2016-09-12
Hi All,

I've managed to found this script (by SubSun), which sift through the Event logs for the Terminal Server:

Get-WinEvent -ComputerName PRODTS03-VM -FilterHashTable @{LogName="Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational";StartTime=(get-date).AddDays(-1);ID=1149} | %{
	New-Object PSObject -Property @{
		MachineName = $_.MachineName
		TimeCreated = $_.TimeCreated
		User = $_.Properties[0].Value            
		Domain = $_.Properties[1].Value            
		SourceIP = $_.Properties[2].Value 
	}
}| Select MachineName,TimeCreated,User,Domain,SourceIP | ft -AutoSize

Open in new window


So I wonder if it is can be configured / modified to filter the Security event ID 4624 only for the user DOMAIN\Administrator like below example events:

Log Name:      Security
Source:        Microsoft-Windows-Security-Auditing
Date:          12/09/2016 12:45:25 PM
Event ID:      4624
Task Category: Logon
Level:         Information
Keywords:      Audit Success
User:          N/A
Computer:      PRODDC01-VM.domain.com
Description:
An account was successfully logged on.

Subject:
	Security ID:		NULL SID
	Account Name:		-
	Account Domain:		-
	Logon ID:		0x0

Logon Type:			3

New Logon:
	Security ID:		MyDomain\Office.Manager
	Account Name:		Office.Manager
	Account Domain:		MyDomain
	Logon ID:		0xf99126a2
	Logon GUID:		{a5bf47f4-d53a-6ff9-2139-a4ceb9e5b284}

Process Information:
	Process ID:		0x0
	Process Name:		-

Network Information:
	Workstation Name:	
	Source Network Address:	10.188.5.34
	Source Port:		60358

Detailed Authentication Information:
	Logon Process:		Kerberos
	Authentication Package:	Kerberos
	Transited Services:	-
	Package Name (NTLM only):	-
	Key Length:		0

This event is generated when a logon session is created. It is generated on the computer that was accessed.

The subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.

The logon type field indicates the kind of logon that occurred. The most common types are 2 (interactive) and 3 (network).

The New Logon fields indicate the account for whom the new logon was created, i.e. the account that was logged on.

The network fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.

The authentication information fields provide detailed information about this specific logon request.
	- Logon GUID is a unique identifier that can be used to correlate this event with a KDC event.
	- Transited services indicate which intermediate services have participated in this logon request.
	- Package name indicates which sub-protocol was used among the NTLM protocols.
	- Key length indicates the length of the generated session key. This will be 0 if no session key was requested.

Open in new window


I need to know the:
        Keywords: Audit Success
        Logon Type: 3
        Date: 12/09/2016 12:45:25 PM
        Security ID: Domain\Administrator
      Source Network Address: 10.188.5.199

Is that possible to customize the script above ?
0
Comment
  • 4
  • 2
  • 2
8 Comments
 
LVL 37

Assisted Solution

by:Bing CISM / CISSP
Bing CISM / CISSP earned 100 total points
ID: 41793632
I would use MS utility Log Parser rathan speed hours to write and debug a script. the utility is well recognised and compatible with most Windows logging sources including Windows Event Logs.

your query criteria can be easily done using Log Paraer's SQL-like querying language.

You may download lownload MS Log Parser here:

https://www.microsoft.com/en-au/download/details.aspx?id=24659

FYI -

https://technet.microsoft.com/en-au/scriptcenter/dd919274.aspx
1
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 41793653
Bing,

There is no GUI with Log Parser and the command to select all domain controllers in the domain with specific event logs is hard to find on the Intenret as well.

But yes, thanks anyway for the response.
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
ID: 41793660
sorry for the typo, just noticed that. typing on touch screen is still a pain for me. correct the typo below though I guess you already know the meaning. :)

"I would use MS utility Log Parser rather than spend hours to write and debug a script."

as I remember there a few GUI versions though they are still based on the utility's command line to run queries.

actually in my understanding, it should be easier to use Log Parser command line to query from multiple servers.
1
 
LVL 39

Accepted Solution

by:
footech earned 400 total points
ID: 41794977
This should do it for your specific need.
Get-WinEvent -ComputerName PRODTS03-VM -FilterHashTable @{LogName="Security";StartTime=(get-date).AddDays(-1);ID=4624;data="administrator"} | % {
    New-Object PSObject -Property @{
        MachineName = $_.MachineName
        TimeCreated = $_.TimeCreated
        User = $_.Properties[5].Value            
        Domain = $_.Properties[6].Value
        LogonType = $_.Properties[8].Value      
        SourceIP = $_.Properties[18].Value
        Keywords = $_.KeywordsDisplayNames -join ";"
        }
} | Select MachineName,TimeCreated,User,Domain,LogonType,SourceIP,Keywords | ft

Open in new window


I added searching for "administrator" in the event message within the filterhashtable parameter.  It's not necessary but it speeds up filtering of the desired events significantly in this case.

The trick is pulling just the desired info out of the event properties, as the data contained (and where) can change with each different type of event.  A more flexible method is to use something like what is described on this page:
https://blogs.technet.microsoft.com/ashleymcglone/2013/08/28/powershell-get-winevent-xml-madness-getting-details-from-event-logs/
1
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 41795244
@Footech, many thanks for the script mate,

is it possible to combine the script above with:

Get-ADDomainController -Filter * | Select-Object name | Get-WinEvent -ComputerName $_.Name -FilterHashTable @{LogName="Security";StartTime=(get-date).AddDays(-1);ID=4624;data="administrator"} | % {
    New-Object PSObject -Property @{
        MachineName = $_.MachineName
        TimeCreated = $_.TimeCreated
        User = $_.Properties[5].Value            
        Domain = $_.Properties[6].Value
        LogonType = $_.Properties[8].Value      
        SourceIP = $_.Properties[18].Value
        Keywords = $_.KeywordsDisplayNames -join ";"
        }
} | Select MachineName,TimeCreated,User,Domain,LogonType,SourceIP,Keywords | ft

Open in new window

0
 
LVL 7

Author Closing Comment

by:Senior IT System Engineer
ID: 41795257
Thanks !
0
 
LVL 39

Expert Comment

by:footech
ID: 41795266
Sure.
Get-ADDomainController -Filter * | Select-Object -expand name | % {
  Get-WinEvent -ComputerName $_ -FilterHashTable @{LogName="Security";StartTime=(get-date).AddDays(-1);ID=4624;data="administrator"} | % {
    New-Object PSObject -Property @{
        MachineName = $_.MachineName
        TimeCreated = $_.TimeCreated
        User = $_.Properties[5].Value            
        Domain = $_.Properties[6].Value
        LogonType = $_.Properties[8].Value      
        SourceIP = $_.Properties[18].Value
        Keywords = $_.KeywordsDisplayNames -join ";"
        }
  }
} | Select MachineName,TimeCreated,User,Domain,LogonType,SourceIP,Keywords | ft

Open in new window

1
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 41795272
You are so awesome ;-)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Big data transfers via information superhighways require special attention and protection. Learn more about the IT-regulations of the country where your server is located. Analyze cloud providers and their encryption systems for safe data transit. S…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now