Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Feb 08, 2018 12:54 pm
Now run this:
Code: Select all
$adspath = 'LDAP://' + ([adsisearcher]"samaccountname=$($env:COMPUTERNAME)$").FindOne().Properties['distinguishedname'][0]
$account = [adsi]$adspath
$account | select *
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu Feb 08, 2018 1:13 pm
newresults.png (73.22 KiB) Viewed 3109 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Feb 08, 2018 1:18 pm
Notice that "Parent" is clearly listed.
Code: Select all
$adspath = 'LDAP://' + ([adsisearcher]"samaccountname=$($env:COMPUTERNAME)$").FindOne().Properties['distinguishedname'][0]
$account = [adsi]$adspath
$account | select parent
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu Feb 08, 2018 1:38 pm
Yes but not when I do this
$adspath = ( [ adsisearcher] "samaccountname=$($env:COMPUTERNAME)$" ) .FindOne( ) .Properties[ 'adspath' ]
( [ adsi] $adspath ) .Parent
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Feb 08, 2018 1:43 pm
Did you run the code I just posted?
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu Feb 08, 2018 1:49 pm
jvierra wrote: ↑ Thu Feb 08, 2018 1:43 pm
Did you run the code I just posted?
Yes it returns the parent. So I should have went back and revisted this post on Page 2
we're discussing a moot point
we have this down to a one-liner, the current script is 3
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Feb 08, 2018 1:53 pm
I have no idea what you are referring to. What is the one-liner?
I posted the last script way back in the beginning. It worked then and works now so I do not understand the issue.
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu Feb 08, 2018 2:04 pm
jvierra wrote: ↑ Thu Feb 08, 2018 1:53 pm
I have no idea what you are referring to. What is the one-liner?
I posted the last script way back in the beginning. It worked then and works now so I do not understand the issue.
(([adsisearcher]"samaccountname=$($env:computername)$").FindOne().Properties['distinguishedname']).split(",")[1] -replace ('OU=')
I said on Page 1 this works,would just like it shorter if possible, but it's not a deal breaker.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Feb 08, 2018 2:14 pm
So what you wanted was the "CN" of the parent OU and not the parent OU.
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked