I have a text file full of TV shows with an ID at the end of their name in each line of a text document. I want to ignore any blank line or ignore any errors
Get-Content -Path "C:\test\text.txt" | ForEach-Object {
$_.Substring($_.Length - 5) -ErrorAction 'SilentlyContinue'
}
I tried to suppress any errors like this but that didn't resolve the issue. How can I skip blank lines or suppress the error messages in a foreach loop?
-ErrorActioncan be used with cmdlets, but not with object methods.