'How to check newly generated logfile on a folder path
I'm working on a simple script wherein I wanted to check if a log contains a specific string and give me an output if it contains the string or not. However the logfile gets updated daily and I wanted to check the most recent file. Is there a command I can add to my script to get the output I needed?. Or is there other way I can do this without using Select-String?.
$SEL = Select-String -Path Pathfile.LOG -Pattern "String"
if ($SEL -ne $null)
{
echo Contains String
}
else
{
echo Not Contains String
}}
Solution 1:[1]
Thanks for your help!. This is what I got and it worked as expected.
Invoke-Command -Computername 'servername' -ScriptBlock {$SEL = Get-ChildItem 'Filepath' | Sort CreationTime -Descending | Select -First 1 | Select-String -Pattern "STRING" -CaseSensitive
if ($SEL -ne $null)
{
echo STRING found
}
else
{
echo STRING not found
}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt |
