r/PowerShell • u/SoyBoy_64 • 4d ago
Script Sharing ADSearch - User/Computer comparison tool
This Active Directory toolkit offers user/computer OU comparisons using fuzzy Levenshtein matching to determine if the computer is in an OU that matches the user's OU. Designed for large enterprise IT audits/asset management of complex (2+ OU levels) AD environments
ADSearch/README.md at main Β· Contoso-Administrator/ADSearch
Edit: Made some edits based on everyone's kind words :)
12
u/JSChronicles 4d ago
Minus points for:
Single character variables
Using new-object instead of pscustomobject in one or two places.
Doing this crap "$sourceLength = $Source.Length", why would you make a variable when you already have the object with the property? Dumb
Write-Host and spacing and ASCII everywhere... God damn didn't know I was reading high school leet code.
Using return... You don't need returns
4
u/uptimefordays 4d ago
LLMs love `return` because every other language uses that to return a value while PowerShell doesnβt.
1
u/skiThooly 10h ago
single character variables drive me crazy when trying to read someone elses script.
-9
u/SoyBoy_64 4d ago edited 4d ago
Thanks for the feedback! Still kinda new at powershell, so any tips help!
I admit the opening banner was solely done for my amusement lol
Edit: these downvotes are getting comical π
3
u/CarrotBusiness2380 4d ago
I'm sorry why does this exist?
What model did you use and what was the prompt? This is overwrought even if it did something useful.
3
u/Nekro_Somnia 4d ago
Besides the question of "why", I ask myself why you'd define the vars that you expect to be changed by someone who runs the script.
Why not define them as parameters and fall back to an output that reminds the user that those need to be defined for the script to work?
A comment based help would be nice as well. Otherwise people need to reference the readme every time they run the script and forgot how to work it.
This might be useful to about 2% of companies in about 2% of their audits, if it were less clunky
3
u/BlackV 4d ago edited 3d ago
your excel version has more functions that the non excel one, like
Get-NormalizedName,Resolve-SamAccountNameand others, why?You declare the same functions multiple times across multiple files, do it once in 1 place
if the only real difference between the two scripts is effectively
export-excelwhy not just have that as a parameter instead of a whole other script (with duplicated functions)?just having parameters in general would help a lot of this
have you looked at
anron the-filterparameter for ad users? (bad wording sorry, changed it)your here string can include formatting, and would clean up a bunch of code (but so would removing it)
$art = @' βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β _ ____ ____ _____ _ ____ ____ _ _ β β / \ | _ \ / ___|| ____| / \ | _ \ / ___| | | | β β / _ \ | | | | ___ \| _| / _ \ | |_) | | | |_| | β β / ___ \| |_| | ___) | |___ / ___ \| _ <| |___| _ | β β /_/ _____/ |____/|_____/_/ __| _\____|_| |_| β β β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β User / Computer OU Lookup Tool β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ '@those variable names, no
not a fan of your million
if/ifelse/elseandreturns
1
u/UserProv_Minotaur 3d ago
Ah, AI Slopfest for something that's better done outside of PowerShell anyway.
1
u/Lonely_Noyaaa 2d ago
The duplicate function declarations across multiple files is the thing I would fix before anything else because maintaining two copies always drifts. A single module with a parameter for Excel export does the same job with half the code.
0
4d ago
[deleted]
2
u/PetuniaPickleswurth 4d ago
We learned from our mistakes, bro. We learned as much from others mistakes.
0
4d ago
[deleted]
2
u/PetuniaPickleswurth 4d ago
Youβre in a very jaded forum. These folks have already learned the lessons that youβre learning now, and for some reason that experience requires those with knowledge to poo poo those that are just learning. Youβre on the right track. The initial work can start with throwing code at a wall, but the end goal has to be most efficient, professional, and secure way to accomplish a task. What you have as a component that you can build a tool from, but you do need constructive criticism to learn.
-4
8
u/TrippTrappTrinn 4d ago
Why would anybody have users and computers in the same OU?Β