Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Looking Ahead
>
Using PowerShell v2.0
How to Search Log File For Number Range Between 60000 and 350000
Last Post 23 May 2010 12:50 PM by
Shay Levy
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Ken
New Member
Posts:3
20 May 2010 04:14 PM
Hi,
I am new to Powershell and would like to know how I can Search a Log File For Number Range Between 60000 and 350000.
Your assistance is greatly appreciated.
Ken
New Member
Posts:3
20 May 2010 06:02 PM
I was able to construct what I was looking for even though I am sure it could be done simpler...
$Dir = "C:\Scripts\Logs\xms logs"
$Folders = get-childitem $Dir
$logfilepath = "C:\Scripts\xmsdata.csv"
$regex = [regex]'(?i)6[0-9][0-9][0-9][0-9]|7[0-9][0-9][0-9][0-9]|8[0-9][0-9][0-9][0-9]|9[0-9][0-9][0-9][0-9]|1[0-9][0-9][0-9][0-9][0-9]|2[0-9][0-9][0-9][0-9][0-9]|3[0-9][0-9][0-9][0-9][0-9]|4[0-9][0-9][0-9][0-9][0-9]ms'
foreach ($subdir in $Folders)
{
$TargetFolder = $subdir
$Files = get-childitem $Dir\$TargetFolder -include *.log -recurse
if ($Files)
{
foreach ($File in $Files)
{
$Sel = Get-ChildItem $path | Get-Content | Foreach { $regex.Matches($_) }
out-file -filepath $logfilepath -append -noclobber -inputobject $Sel
}
}
}
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
23 May 2010 12:50 PM
Check this post for a utility to create a numeric range Regular Expression
http://blogs.microsoft.co.il/blogs/...ssion.aspx
Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Looking Ahead
>
Using PowerShell v2.0
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2