Monday, July 2, 2012

Find Text Activity Alternative

I've encountered an issue a few times now where I need to use the Find Text activity to search a rather large (~20MB) txt or log file for a specific string.  The PolicyModule process would spike to around 25% proc utilization for every Runbook Instance running.  Set the job concurrency to four or more instances and you can do the math to see this becomes an issue :).  On top of that....the activity would take around 20 minutes to complete for each instance.

Once again PowerShell comes to the rescue.  You can easily port the activity over to the Run .Net Script activity and set the Published Data field for "result" using the below example.

$file = "C:\temp\myfiletosearch.txt"
$searchtext = "Specific string to find here"

$content = Get-Content -Path $file | Select | Where {($_ -like "*$searchtext*")}

If ($content -ne $null)
{
    $result = "Text Found"
}
Else
{
    $result = "Text NOT Found"
}

No comments:

Post a Comment