Thanks for the suggestion, Actually the above one is just a sample having 7 domain names, but in actual scenario it may have more than 300+ domains, so it will be difficult to pass each domain name.
I was trying to use convertfrom-string, but I can’t get it to work.
$template = @'
{Domain*:a.org}
{Domain*:b.com}
'@
$testText = @'
A worker process serving application pool 'a.org(domain)(4.0)(pool)' has requested a recycle because it reached its private bytes memory limit.
A worker process serving application pool 'b.com(domain)(2.0)(pool)' has requested a recycle because it reached its private bytes memory limit.
'@
$testText | convertfrom-string -templatecontent $template
Domain
------
A worker process serving application pool 'a.org(domain)(4.0)(pool)' has requested a recycle because it reached its private bytes memory limit.
A worker process serving application pool 'b.com(domain)(2.0)(pool)' has requested a recycle because it reached its private bytes memory limit.
Will Anderson - This domains are actually hosted on IIS, and not all of them will show application pool recycle error. so fetching from AD will not be possible.
If you are not sure how large this log file will be, I recommend using switch statement.
# Match and add each domain name to list
$log = Get-ChildItem .\event.log
$nobj = New-Object System.Collections.ArrayList
switch -regex -File $log {
"pool '(?'dn'.*)\(domain\).*requested a recycle"
{[void]($nobj.add($Matches['dn']))}
}
# Display number of domain name
$nobj | Group-Object | Select-Object Name,Count
‘(?‘dn’.*)’ is a named capture group. It will capture the domain name or in this case all text between the words ‘pool’ and ‘domain.’ Once captured, a hashtable ($Matches) is created.
() = text in parentheses will be captured
‘.*’ = any number of characters
?‘dn’ = give the capture group the name ‘dn’
I was reading about capture groups here, but the format used greater than and less than signs (this forum can’t show them) instead of single quotes. Regular Expressions - PowerShell - SS64.com