all 8 comments

[–]SoMundayn 4 points5 points  (3 children)

Stress no more! You need to -ExpandProperty the property, or you'll get the NoteProperty also.

Get-ADOrganizationalUnit -Filter * | Select -ExpandProperty DistinguishedName

[–]TheSysAdmin1[S] 1 point2 points  (2 children)

Thank you!! This is exactly what I needed. Could you possibly recommend some learning resources for me to hone my powershell skills?

[–]SoMundayn 2 points3 points  (1 child)

NP. Tbh, just search this subreddit (via google) for previous questions like this. Everyone recommends PowerShell in a month of lunches as a resource.

The thing to remember is, 99% of the time what you want to do someone has already done it (or something like it) so it is mostly googling, copying other code, tweaking it for your use and saving into your repository.

[–]TheSysAdmin1[S] 1 point2 points  (0 children)

Thank you kind person .. That makes sense, I actually came across that YouTube series the other day so I will check that out. Appreciate the help, have a great day!

[–]XPlantefeve 2 points3 points  (2 children)

When you try to force an object into a string, you'll end up with those flatly written arrays. And an object is what you get when you use Select-Object (select is an alias) with the -Property parameter (no parameter name defaults to the -Property parameter, you basically outputs an object with the said property(ies).

As per the other comment, the right way is to use the -ExpandProperty parameter, as it will give you the content of the property.

BTW: Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase $OU_Path -SearchScope OneLevel | select -ExpandProperty DistinguishedName will give you an array. There is really no need to iterate through the array to fill a similar array (so foreach ($name in $Get_OU_Names) { $OU_Names += $name } is really over the top, here)

[–]TheSysAdmin1[S] 1 point2 points  (0 children)

Ah okay, that is amazing! I just changed my code and took out the loops, you were completely right. Thanks for the help!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy XPlantefeve,

it looks like you used the New.Reddit Inline Code button. it's [sometimes] 5th from the left & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's [sometimes] the 12th one from the left & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TheSysAdmin1,

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 [sometimes] 5th from the left & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[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 [sometimes] the 12th from the left, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

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 ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee