I am trying to make a script in Powershell to make searching for errors in logfiles easier. I need to extract last 8 digits of a given file name in one direction to use it as a search string later on, extract its date of creation to put it in the logile name where I will be searching and then run a command to search for the errors. Preferably I would like to transfer the output to a txt file. So far I managed to do sth like this
$errorFiles = Get-ChildItem -Path 'C:\Users\admin\Desktop\Invalid' -Filter '*.txt' -File$date = (gi C:\Users\admin\Desktop\Invalid).CreationTime.ToString('yyyy-MM-dd') foreach ($file in $errorFiles) { FINDSTR "$errorFiles.Substring($configFiles.Length-8)" server.log.$($date) C:\Users\Desktop\logs}
can someone brutally honest tell me how to extract the last 8 digits of a file correctly and what is wrong with foreach? is it even possible to use FINDSTR in a loop or should there be a different command?
I am a total beginner in Powershell so please do not kill me :)