Skip to content

Instantly share code, notes, and snippets.

@janegilring
Created May 28, 2013 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janegilring/5664784 to your computer and use it in GitHub Desktop.
Save janegilring/5664784 to your computer and use it in GitHub Desktop.
Entry from the 2013 Scripting Games Beginner Event 5, reviewed at blog.powershell.no
<#
.SYNOPSIS
Gets the Unique IP Information from a directory of *.log files.
.DESCRIPTION
This script was written for the Event 5 Beginners Track in the 2013 Scripting Games.
It will look through IIS logs in a directory and all sub directories and pull out a
list of unique ip's.
.PARAMETER PathToLogs
Path to the Log files (Example C:\Temp\LogFiles\)
.EXAMPLE
.\GetUniqueIPs.ps1 -PathToLogs C:\Temp\LogFiles
#>
param(
[Parameter(Mandatory=$True)][string]$PathtoLogs
)
get-childitem $PathtoLogs -Recurse -Include *.Log |
select-string -Pattern \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b -allmatches |
ForEach {$_.Matches} |
Foreach {$_.Value} |
Select-Object -Unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment