In August 2025 I wrote a post on testing security functions with Pester. The example was Test-PathTraversal, a function from what’s now OrphanedSid that checks a path stays inside a base folder, follows junctions and symbolic links to their targets, and flags ..\ and its encoded forms. The post walks through the test suite for it, context by context.
Nothing in the module ever called it. No command passed a path to it, and no private function did either. It shipped in 1.0.0 and 1.0.1, with its tests counting toward coverage, and it had two bugs. 1.1.0 deleted it, along with 42 other private functions that nothing reached. The links in that post now point at the v1.0.1 tag, because the file isn’t on main anymore.
I’ll call it growth that I read my own 2025 tests with disgust and deleted them.
A junction that resolved to “C”
The first bug in Test-PathTraversal was in how it followed a junction:
On Windows PowerShell 5.1, Target is a string array, and [0] is the target. On PowerShell 7 it’s a single string, and [0] is its first character. A junction in a temp folder pointing at C:\Windows:
C isn’t a rooted path, so the function joined it to the link’s folder and got <link folder>\C. That’s inside the base folder, so a junction out to C:\Windows passed as safe. On 5.1, where the 2025 post’s Pester 3.4 is the built-in version, the code was right.
The junction bug makes it three times in this series that a string got indexed where an array was expected, after the C in the restore and the r for a user object.
The second bug was the containment check itself:
| |
C:\BaseEvil\x starts with C:\Base, so a sibling folder counted as inside.
Bugs in code that never ran
The cleanup started from tests. When the test rewrite made every test able to fail, a correct test that failed was kept and skipped, and the bug went into an issue. Several of those issues were in functions with no caller. A few of them:
| Function | What it did wrong |
|---|---|
Test-BackupSignature | Matched the format string with -contains, which is culture-aware. PSSecurityBackup_v2.1 with a null character inserted still matched, even with -ceq. Only an ordinal comparison tells them apart. |
Complete-RestoreOperation | Summed TimeSpan values with Measure-Object -Sum, which fails with Input object "00:00:03" is not numeric. on 5.1 and 7, so the total was always empty. |
Test-BackupFileIntegrity | Compared hashes with case-insensitive -ne, the same bug the real restore check had. Its outer catch set an error message and left IsValid = $true. |
Protect-LogMessage | Stripped control characters before ANSI escape sequences, so the ESC was gone before the sequence could match, and [31m stayed in the text. Its -PreserveNewlines switch had no effect. |
Get-LoggingState | Reported log entry counts from a table that only Update-LoggingMetrics wrote to, and nothing called that, so it always said zero. |
Find-BackupFile | Returned ,$results, so piping it to Select-Object gave one blank row. The troubleshooting guide’s snippet worked around it. |
The null character, the TimeSpan sum and the junction are plain PowerShell behavior, and I reran all three on my machine this week, on 5.1 and 7.
The non-function case was similar. Write-ProcessingSummary had an -AutomationMode switch that no caller passed, and the block behind it had two log lines pasted in from the main summary.
Fix them or delete them
Every issue offered both. Fix the defect, or remove the function. Deleting won each time, for the same reason: a command already did that job another way.
Test-BackupValidationandTest-BackupFileIntegrity: a restore validates a backup withTest-BackupIntegrityGet-SafeFileName:New-ACLBackupsanitizes backup names itselfInvoke-GarbageCollection: a run collects garbage throughInvoke-Cleanup
The last one on that list got fixed before it got deleted. Invoke-GarbageCollection -CompactLOH reported large object heap compaction it never asked .NET for. The fix went in on November 10, with a note in the pull request that nothing in the module passed -CompactLOH. On November 11 the function was deleted.
The helpers with no caller that stayed were Clear-SIDValidationCache, Get-SIDValidationCacheStat, Test-MemoryThreshold and Get-MemoryUsageReport. The troubleshooting guides tell you to call them through the module’s scope when you’re diagnosing a run, so they have a caller. It just isn’t code.
Finding what nothing calls
The 43 came out in four rounds over about 28 hours. Each round found its share a different way: 19 from tests the rewrite had skipped, 5 from the documentation pass, 1 from a later issue that also caught the summary block, and 18 from a parser search of Classes, Private and Public.
A search for the name isn’t enough. Get-LogFileSummary was called, by three functions that nothing called. A guarded fallback stub can define a name twice. Class methods call module functions, so a class is a starting point too. Reachability handles all of that: start from the exported commands and the classes, follow every call, and whatever’s left was never reached.
For this post I wrote that as one scan and ran it against both tags:
| |
| Tag | Functions never reached |
|---|---|
v1.0.1 | 47: the 43 that were removed, plus the 4 diagnostic helpers |
v1.1.0 | 4: the diagnostic helpers |
One pass at 1.0.1 would’ve found everything the four rounds did. The first version of the scan gave 76, because it counted class methods as functions and let a fallback stub’s calls replace the real function’s. Those two fixes are the FunctionMemberAst check and the ContainsKey line.
It only follows calls written out by name. A call through & $name or Get-Command wouldn’t count as one, so the last round also searched for names inside strings. It found none.
Keeping a removed name from coming back is the contract test’s job. The live-run post covers that test: it fails when the module calls a function or parameter that doesn’t exist.
What came out
| 1.0.1 | 1.1.0 | |
|---|---|---|
| Private function files | 57 | 47 |
Function names in Private, Public, Classes | 123 | 85 |
| Lines in the removed functions | 4,468 |
The 85 includes five functions 1.1.0 added for fixes earlier in this series, such as ConvertTo-DistinguishedName. The last three rounds took 332 tests with them, every one a test of removed code. Coverage went up wherever the pull requests measured it, because untested lines in the deleted functions went too.
Those tests passed. They ran code no command reached, and they counted toward the 90% gate the same as the tests of code that changes ACLs.
