r/PowerShell • • 21d 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 :)

0 Upvotes

21 comments sorted by

View all comments

3

u/BlackV 21d ago edited 21d ago
  • your excel version has more functions that the non excel one, like Get-NormalizedName, Resolve-SamAccountName and 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-excel why 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 anr on the -filter parameter 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/else and returns

2

u/BlackV 21d ago

from SoyBoy_64

"What do you mean by this? have you looked at the -anr parameter for ad users?"

Parameter was probably the wrong word, have a look at

$displayName = 'bob'
Get-ADUser -Filter "ANR -eq '$($displayName)'"

Some write ups

https://learn.microsoft.com/en-us/archive/technet-wiki/22653.active-directory-ambiguous-name-resolution

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/1a9177f4-0272-4ab8-aa22-3c3eafd39e4b

https://adsecurity.org/?p=356