How it works...
The Trace parameter helps trace the error. By default, the trace level is 0. Therefore, no trace output is shown. When the trace level is set to 1, it only shows each of the lines that were run; when set to 2, the debug information is more verbose: PowerShell tells you what it is doing at each step.
At step 4, we can see that the issue seems to be with what was within $Name. Therefore, we set a breakpoint at line 10. (In fact, setting the breakpoint at 8 also would have worked.) The execution pauses at the breakpoint, and, at this point, you can look at the value of $Count by simply calling it. Tracing back to what could have caused this wrong count, we arrive at line 3, where we can see that the type of $Name was changed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access