Team, Thanks in advance, I'm an ITPro and learning PowerShell. I've a log file which has the data in below format. I've attached the image. I'm finding all the line which has finished transfer in it and then running foreach loop to find the line in which the date matches the current date using -eq operator
I wanted to then get the specific file name from that current line where the foreach loop is running. Example from my sample : first finished transfer line in the log matches the current date hence i wanted to get the file name which is HardwareEvents.evtx.
But I'm unable to find any method which can help me parse a file name in the current running for each line.
If i get the file name i can then delete the file using powersell cmdlet.
$var = Select-String -Path "C:\Creds\AzCopyVerbose.log" -Pattern 'Finished Transfer' | `
Select-Object -Last 20 | ForEach-Object `
{
if (($_.Line).Substring(1,10) -eq (Get-Date).ToString('yyyy/MM/dd'))
{
$_.Line. // There is no method which I'm aware of need help in this if statement
}
Else {Write-Host "The date present in the azcopy verbose log is older"}
}
