Cannot index into a null array Cannot index into a null array powershell powershell

Cannot index into a null array


The issue here is that you're trying to index into an array that has zero length (nothing in it at all) during one of the loops. I assume this is because one of the lines being processed has no matches at all.

You could use something to check if there are any matches at all before trying to access the index.

Something like..

if ($Search.Matches.Count -gt 0) {}

If you want to suppress the errors, then you can use something like

-errorAction SilentlyContinue

to suppress the errors.