The commands in OrphanedSid return objects so you can keep going with them in the pipeline. The first post showed it with the same example the README opens its usage section with:
Point it at every top-level OU and see which dead SIDs show up most. On 1.0.0 and 1.0.1, that example dropped every OU you piped in and searched the domain root. Piping the same objects into Remove-OrphanedSid did the same thing, and piping them into Restore-OrphanedSidBackup failed to bind at all. It’s issue #79.
Less than two weeks before 1.0.0 shipped, I’d ended a post about CaOutcome with “A README example is a test case I haven’t written yet.” This was another one.
The right answer from 303 objects
I ran the README’s pipe again on the lab DC on November 19, piping one OU into Find-OrphanedSid from the 1.0.1 and 1.1.0 packages, each in a fresh process:
| Module | Search base in the log | Objects read | Time | Results |
|---|---|---|---|---|
| 1.0.1 | DC=ad,DC=homelabdomain,DC=xyz | 303 | 78 s | 2 |
| 1.1.0 | OU=Orphaned,OU=EdgeCases,... | 3 | 6 s | 2 |
Both runs returned the same two orphans on the same two groups. In my lab, the only seeded orphans live in that OU, so a domain-wide search finds the same two. The output looked correct. The only signs were a warning and a log line:
A real directory has orphans everywhere. When #79 was filed, a -WhatIf preview of Get-ADOrganizationalUnit <one OU> | Remove-OrphanedSid listed 7 objects, and 6 of them were outside the piped OU. Without -WhatIf and with -Force, that’s a removal across the domain from a command that named one OU.
Restore failed in a safer way:
| |
An object that answers every question
Piping a DN string worked. Piping a [pscustomobject] with a DistinguishedName property worked. Only real AD objects failed, and the AD module explains why. On the DC:
The AD module’s adapter answers any property name you ask for. If the attribute isn’t there, you get an empty collection back, not $null.
Now look at the 1.0.1 parameter:
A string was meant to bind by value, and an object by its DistinguishedName through the alias. To see what PowerShell does with an AD object, I put the same parameter on a small test function on the DC and ran Trace-Command -Name ParameterBinding. Trimmed to the pipeline part:
| |
By value is tried first without type conversion, and an ADOrganizationalUnit isn’t a string, so it’s skipped. By property name comes next, and PowerShell asks for the parameter’s own name before any alias. It asked the OU for SearchBase, the adapter handed back an empty collection, and that bound as an empty string[]. The binding succeeded, so the DistinguishedName alias was never tried.
The process block saw nothing to add, and end did what it was written to do with an empty list:
Restore-OrphanedSidBackup had the same shape on -TargetObjectDN, but it’s Mandatory, so the empty array failed binding instead of falling back.
The CaOutcome post’s rule applies here too: pipe the shape your real upstream produces. The unit tests piped strings and [pscustomobject]s, and both bind correctly. Only an object whose adapter claims every property shows the failure.
Reading the DN myself
1.1.0 stops asking PowerShell to find the DN. All three parameters are [object[]], bound by value only:
| |
An [object[]] parameter accepts anything by value, so every piped item reaches process as itself. A new private function, ConvertTo-DistinguishedName, reads each one:
| |
Strings, hashtables, Import-Csv rows and AD objects all work. A blank value is dropped. Anything with no DN gets an error naming its type. On the DC, with 1.1.0:
| |
| |
That error alone isn’t the fix. Bad input that still fell through to the domain root would be #79 again. So the commands now tell “no -SearchBase at all” apart from “a -SearchBase that held nothing usable”:
| |
$searchBaseGiven is set in process from $PSBoundParameters, so it’s true for piped input too. Restore-OrphanedSidBackup stops with No usable restore target in the input. One behavior change came with this, and it’s in the changelog: -SearchBase ' ' used to search the domain root, and now it stops.
The same OU piped into 1.1.0 is the second row of the table: 3 objects, one search base, no warning.
A test double that answers like AD
The new tests needed something that fails the way an AD object does, on a runner without RSAT. The stand-in carries a DistinguishedName plus the two parameter names as empty collections. That’s the shape the adapter presents:
The test for Find pipes two of them and checks that the domain was never asked for its root:
| |
With the three public files reverted to the code before the fix, 9 of the new tests fail, including the domain-root fallback for Find and Remove and Restore’s empty-array error.
A relative path that pointed at the profile
Issue #80 was filed less than a minute after #79, and it’s the same kind of bug: a value that looked fine when it came in and meant something else by the time it was used.
| |
The parameter’s ValidateScript checked the folder with Test-Path, which resolves against your PowerShell location, so validation passed. Then the restore workflow normalized the path with [System.IO.Path]::GetFullPath, which resolves against the process working directory. Set-Location doesn’t change that, and it’s usually your profile folder. On my machine, after Set-Location C:\Windows\Temp, same result on 5.1 and 7:
The restore’s own help example, -BackupPath '.\Backup\20260703_104232', didn’t work as written. Remove-OrphanedSid -BackupPath .\bk did, because the backup code wrote its files with cmdlets that resolve against your location, and the backup fix in 1.1.0 had already switched it to the PowerShell-aware call. 1.1.0 uses it in all four places the restore normalizes a path:
New-ACLBackup resolves its folder the same way. That’s how it measures the full path for the 260-character budget in the backup post. The new tests set [Environment]::CurrentDirectory and the PowerShell location to different folders before restoring from a relative path. If the two match, the bug can’t show, so the test makes sure they don’t.
