<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/an-odd-sort-ly3rafhpl" -->

---
title: An Odd Sort | daily.dev
description: A reader-submitted PowerShell script for querying Active Directory user data is dissected as a classic example of bad code. The script attempts alphabetical...
canonical: https://daily.dev/posts/an-odd-sort-ly3rafhpl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: An Odd Sort | daily.dev
og:description: A reader-submitted PowerShell script for querying Active Directory user data is dissected as a classic example of bad code. The script attempts alphabetical...
og:url: https://daily.dev/posts/an-odd-sort-ly3rafhpl
og:image: https://api.daily.dev/og/posts/ly3rafhpL.png
og:image:alt: An Odd Sort
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# An Odd Sort

**[The Daily WTF](https://daily.dev/sources/thedailywtf)** · 2 min read · 0 upvotes · 0 comments

## Summary

A reader-submitted PowerShell script for querying Active Directory user data is dissected as a classic example of bad code. The script attempts alphabetical sorting by looping through letters a-z and filtering names starting with each letter, without ever actually sorting the results. It then redundantly performs a second search for each user just to fetch fields it already excluded from the first query, and uses a loop over FindAll() results instead of the simpler FindOne() despite expecting a single match. Despite its inefficiency, the script survives because a manager likes the CSV output it produces.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://thedailywtf.com/articles/an-odd-sort>

## Similar posts on daily.dev

- [Analyzing Vibe-Coded AD Enumeration](https://daily.dev/posts/analyzing-vibe-coded-ad-enumeration-riuoelkq3) · Huntress Blog · 0 upvotes · 0 comments
- [Sort This Out](https://daily.dev/posts/sort-this-out-0cx7s10qv) · The Daily WTF · 0 upvotes · 0 comments
- [PowerShell is way more powerful than most Windows users realize](https://daily.dev/posts/powershell-is-way-more-powerful-than-most-windows-users-realize-fjbizflgi) · XDA Developers · 0 upvotes · 0 comments

---

Tags: [#powershell](https://daily.dev/tags/powershell), [#active-directory](https://daily.dev/tags/active-directory)

[View this post on daily.dev](https://daily.dev/posts/an-odd-sort-ly3rafhpl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"An Odd Sort","url":"https://daily.dev/posts/an-odd-sort-ly3rafhpl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/an-odd-sort-ly3rafhpl"},"datePublished":"2026-09-15T11:22:42.974Z","dateModified":"2026-09-15T11:22:57.240Z","description":"A reader-submitted PowerShell script for querying Active Directory user data is dissected as a classic example of bad code. The script attempts alphabetical...","image":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","thumbnailUrl":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","isAccessibleForFree":true,"articleSection":"The Daily WTF","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"The Daily WTF","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/d21a6aa61a7244d893a3b3284df8e2ef","url":"https://daily.dev/sources/thedailywtf"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/an-odd-sort-ly3rafhpl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"powershell,active-directory","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"The Daily WTF","item":"https://daily.dev/sources/thedailywtf"},{"@type":"ListItem","position":3,"name":"An Odd Sort"}]}
```

