Remy Porter published this CodeSOD item in The Daily WTF on 15 September 2026. Alice submitted a PowerShell script for a routine Active Directory report that prints each user’s name and last logon time. She presented the listing as cleaned up and indented.

The script walks from a through z. For each letter, it creates a `System.DirectoryServices.DirectoryEntry` and a `System.DirectoryServices.DirectorySearcher`, filters names with that initial, requests the `name` property, and processes the results. It then creates another `DirectorySearcher` for each returned name, searches for `objectCategory=User` with the matching `sAMAccountName`, and outputs `name` together with `lastLogon`.

The letter loop groups entries by initial. Their order inside each group remains undefined, so `albert` and `alice` are not guaranteed to appear in sequence. The first query loads only `name`. The second retrieves account data, while the output uses two fields. For a lookup expected to return one account, the script loops over `FindAll()`. `FindOne()` matches that search target. A manager relies on the resulting CSV for Excel, making the script mission critical.