January 16, 2025 at 1:51 pm
How can I modify this script to do a couple more features.
1) process only the most current file from the folder.
2) if I find 4 occurrences of the word FULL in that most recent file .. then issue an email
many thanks to the people in this forum.
# Define the path to the directory containing text files and the keywords to search for
$directoryPath = "\\xsxgg1\pub\nepr\performance\aimonitor\mfgprod\"
$keywords = @("FULL")
# Get all text files in the directory
$textFiles = Get-ChildItem -Path $directoryPath -Filter *.*
# Search for the keywords in each text file
foreach ($file in $textFiles) {
$results = Select-String -Path $file.FullName -Pattern $keywords
$results | ForEach-Object {
Write-Output "Found '$($_.Matches.Value)' in file '$($file.Name)' at line $($_.LineNumber): $($_.Line)"
}
}
January 16, 2025 at 3:42 pm
Okay I have the getting most current file now.
$textFiles = Get-ChildItem -Path $directoryPath |?{-not $_.PsIsContainer} | Sort CreationTime | Select -Last 1
How do I count found Keyword now if Equal to or GT 4 issue email
January 16, 2025 at 4:24 pm
okay now I'm close on counting keyword but I have something wrong I know .value isn't correct..
$keywords = @("EMPTY")
$textFiles = Get-ChildItem -Path $directoryPath |?{-not $_.PsIsContainer} | Sort CreationTime | Select -Last 1
# Search for the keywords in each text file
foreach ($file in $textFiles) {
$results = Select-String -Path $file.FullName -Pattern $keywords
$results | ForEach-Object {
# Sum the numbers found in the line
foreach ($number in $results) {
$totalSum += [int]$number.Value
}
$totalSum ----????????????
}
}
January 19, 2025 at 4:29 pm
Any suggestions or help..
Many thanks.
January 20, 2025 at 3:40 am
Any suggestions or help..
Many thanks.
I don't know 5hit from Shinola in Powershell and so I tried something different... here's the link to the thread I worked through...
https://www.perplexity.ai/search/using-powershell-how-to-search-hGZTTLw2Rmi4v81v3IwqEA#2
I'm not testing it for you though. You have to have some of the fun. Make sure that you read both questions leading up to that final 3rd question. You might also want to read some of the links it provides. And, always remember, it's "just a consensus" engine when it comes to such things so you must ALWAYS test things including any and all "Edge Cases".
p.s. Saying "AI it" just doesn't have the same ring as "Google it" does, though.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2025 at 3:46 am
Bruin wrote:Any suggestions or help..
Many thanks.
I don't know 5hit from Shinola in Powershell and so I tried something different... here's the link to the thread I worked through...
https://www.perplexity.ai/search/using-powershell-how-to-search-hGZTTLw2Rmi4v81v3IwqEA#2
I'm not testing it for you though. You have to have some of the fun. Make sure that you read both questions leading up to that final 3rd question. You might also want to read some of the links it provides. And, always remember, it's "just a consensus" engine when it comes to such things so you must ALWAYS test things including any and all "Edge Cases".
p.s. Saying "AI it" just doesn't have the same ring as "Google it" does, though.
p.p.s. I am NOT responsible for any answers that AI may or may not provide... Period!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy