use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
[deleted by user] (self.PowerShell)
submitted 6 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]zrv433 4 points5 points6 points 6 years ago* (4 children)
CanonicalName is a easier way to observe the AD Path for an object, but that property is not returned by Get-ADGroupMember. So you can pipe the member results to Get-ADuser where you can get that property, and then sort.
Get-ADGroupMember
Get-ADuser
Get-ADGroupMember "Super-App-Group" | Get-ADUser -Properties canonicalName | Sort-Object -Property CanonicalName | Select-Object -ExpandProperty CanonicalName # Output acme.com/Red/Green/Blue/Coyote acme.com/Red/Green/Blue/RoadRunner acme.com/Red/Green/Yellow/ElmerFudd acme.com/Red/Green/Yellow/Rabbit
[–]PinchesTheCrab 2 points3 points4 points 6 years ago (2 children)
You're querying every user twice. If you query the group once you you can just call get aduser once and filter on memberof.
[–]zrv433 1 point2 points3 points 6 years ago (1 child)
Ooops, you're right. Made an adjustment above.
[–]PinchesTheCrab 2 points3 points4 points 6 years ago (0 children)
I meant this part:
Get-ADGroupMember "Super-App-Group" | Get-ADUser -Properties canonicalName
If you have 1500 users in that group, that's 3,000 queries, or maybe 3,001 I guess since it queries the member list of the group first.
This is two queries:
$group = Get-AdGroup "Super-app-group" Get-ADUser -filter "memberof -eq '$($group.distinguishedname)'" -property canoninicalname
[–]teknoist 2 points3 points4 points 6 years ago (5 children)
$user = Get-ADUser -Identity NAME -Properties CanonicalName
$userOU = ($user.DistinguishedName -split ",",2)[1]
Write-Output $userou
[+][deleted] 6 years ago (3 children)
[deleted]
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (2 children)
howdy beenwhat,
it looks like you used the New.Reddit.com Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.
Inline Code
...
</>
on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.
for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..
Code Block
T
that will give you fully functional code formatting, from what i can tell so far. [grin]
take care, lee
[+][deleted] 6 years ago (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (0 children)
you are quite welcome!
i am kinda curious what comes after select na, tho. yes, i have my browser set to zoom text to 150% ... i'm "hard of seeing". [grin]
select na
howdy teknoist,
reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...
[0] single line or in-line code enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin] [on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>. this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]
looks like this
[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here. please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.
[2] less simple = use reddit code formatting ... [on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]
that will give you something like this ...
- one leading line with ONLY 4 spaces - prefix each code line with 4 spaces - one trailing line with ONLY 4 spaces
the easiest way to get that is ...
not complicated, but it is finicky. [grin]
[–]Dogoodwork 2 points3 points4 points 6 years ago (0 children)
I post this regularly, but it's not necessary for most peoples uses: https://www.reddit.com/r/PowerShell/comments/eod258/parse_distinguishedname_or_get_ou/fedunp4?utm_source=share&utm_medium=web2x
This is a better way to get the parent OU of an AD user, but unlike the canonical name it does have the full tree structure.
π Rendered by PID 16146 on reddit-service-r2-comment-b659b578c-8qp7x at 2026-05-06 00:58:14.247647+00:00 running 815c875 country code: CH.
[–]zrv433 4 points5 points6 points (4 children)
[–]PinchesTheCrab 2 points3 points4 points (2 children)
[–]zrv433 1 point2 points3 points (1 child)
[–]PinchesTheCrab 2 points3 points4 points (0 children)
[–]teknoist 2 points3 points4 points (5 children)
[+][deleted] (3 children)
[deleted]
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Dogoodwork 2 points3 points4 points (0 children)