Unsuccessful with this code in appending the date to a flat text file when a pattern is matched in the file. Verified that the pattern is found and but not able to get the add-content to function. NOTE: the wait is used in order to wait until the keyword = Idle is written to the file.
my code is here:
$File = "AutoDE45oService_AP.$(get-date -Format yyMMdd).log"
$Path = "C:\Users\user"
$result = Get-ChildItem $Path -recurse | Where-Object { $_.Name -match $File }
$containsIdle = Get-Content $result.FullName -Tail 1 -Wait | Select-string -Pattern "Idle" -Quiet
If($containsIdle -contains $true)
{
Add-Content $result.FullName -Value (Get-Date) -PassThru
}