extract from DN of the object OU in the domain's root

Hi folks,

sorry for my English

I need extract from DN of the object OU in the domain's root ( ou=development or ou=staff)
 
                                                                       dc= Biomed  
                                                                             |
                                                                             |                                    
                                                  development _  _|___ou=staff
                                                                       |              |
                                                                       |              |
                                   win7 desktops    --------               -------ou=research
                                           |                                            |
                                      comp1                                        ------ou=accounting
                                                                                                        |
                                                                                                           cn=john's comp

DN >cn="john comp", ou=accounting,ou=staff, dc=biomed



please, help
nesher13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Are you saying that you have an object with a DN like "cn=john's comp,ou=accounting,ou=research,ou=staff,dc=biomed" and you need it to be
"cn=john's comp,ou=accounting,ou=staff,dc=biomed" (in essence removing the "ou=research" portion)?
0
nesher13Author Commented:
footech

yes
0
footechCommented:
The distinguishedName is just a string, so you can do a replace operation on it, replacing the desired text (in this case ",ou=research"), with nothing.  It's hard to give a complete example without knowing how you're using it, but hopefully this example shows the syntax well enough for you.
Given a particular string this would work.
"cn=john's comp,ou=accounting,ou=research,ou=staff,dc=biomed" -replace ",ou=research"

Open in new window


Here's an example working on a list of computers retrieved from AD.
Get-ADComputer -filter * | Select DistinguishedName,@{n="new DN";e={$_.DistinguishedName -replace ",ou=research"}}

Open in new window

0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

nesher13Author Commented:
footech,

I do not quite understand your answer and how to apply it in my task

I want to run following pipe:

Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select replasementDN, name | sort replasementDN

Many thanks
0
footechCommented:
The second example in my previous post is applicable.  It uses what is known as a "calculated property".  The Select command is used to create a new property for the object that is calculated from other information.  Here it is integrated with the command you want to run.
Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select @{n="replacementDN";e={$_.DistinguishedName -replace ",ou=research"}}, name | sort replacementDN

Open in new window

0
nesher13Author Commented:
footech

I am sorry, but this is not working.

I probably do not accurately formulate the problem. In the picture is not visible multilevel structure of the domain. I not want to see in replacementDN contained domain,hierarchy ou's or CN . I quote a few lines of output:

replacementDN                                                                     name



CN=ACC2 Desktops,DC=tr,DC=Biomed         (does not exist in the root domain)                                                         ACC2

CN=ADM-PC,OU=OLD Comps,DC=Biomed      ( there is CN )                                                                                    ADM-PC

CN=ADREYGXPV2,OU=WXP Desktops,OU=Bio Institute,DC=Biomed  (2 OU +CN)                                            ADREYGXPV2

CN=ALBERTS-PC1,OU=W7,OU=Bio Institute,DC=Biomed       (2 OU +CN)                                                              ALBERTS-PC1

CN=AMIT13 Desktops,DC=Biomed          (does not exist in the root domain)                                                        AMIT13

Also, I get output not only from ou Amit (I use Amit  instead Research). But and of several OU's on top-level
0
footechCommented:
I'm sorry, but I don't understand what you want.

Maybe I'll understand if you explain the following:
- what command you want to run
- what the current output is
- what you want the output to be
0
nesher13Author Commented:
footech

I am running following pipeline:
 Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select @{n="replacementDN";e={$_.DistinguishedName -replace ",ou=Amit"}}, name | sort replacementDN | export-csv c:\temp\replasment-DN.csv

Open in new window

Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select @{n="replacementDN";e={$_.DistinguishedName -replace ",ou=Amit"}}, name | sort replacementDN | export-csv c:\temp\replasment-DN.csv

instead of the previous output, I would like to receive:

replacementDN                                                    Name


Amit                                                                                      ACC2

OLD Comps                                                                          ADM-PC

Bio Institute                                                                           ADREYGXPV2

Bio Institute                                                                           Albert-pc1

AMIT                                                                                      Amit13
0
footechCommented:
What's the output if you just run
Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select distinguishedname, name | sort distinguishedname

Open in new window

0
nesher13Author Commented:
footech,

I am run Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select distinguishedname, name | sort distinguishedname
                                         
CN=AMIT13,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=technion,DC=..
CN=AMIT15,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=technion,DC=..
CN=AMIT20,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=technion,DC=..
CN=AMIT8,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=technion,DC=a..
CN=AMITSERVER,OU=OLD Comps,DC=tr,DC=technion,DC=ac,DC=il
CN=AMITUSER19,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=technion..
CN=AMITUSER2,OU=OLD Comps,DC=tr,DC=technion,DC=ac,DC=il
CN=AMITUSER9,OU=OLD Comps,DC=tr,DC=technion,DC=ac,DC=il
CN=ANAT-LAP,OU=OLD Comps,DC=tr,DC=technion,DC=ac,DC=il
CN=ATL,OU=WinXPWMI,DC=Biomed
CN=ACC2,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=Biomed
CN=ACC3,OU=AMIT Desktops,OU=AMIT,DC=Biomed
CN=ACC6,OU=AMIT Desktops,OU=AMIT,DC=Biomed
CN=AUTHRIZATIONMMI,OU=OLD Comps,DC=Biomed
CN=AVIAVXPSP2,OU=OLD Comps,DC=Biomed
CN=B-D_COMP1,OU=OLD Comps,DC=Biomed
CN=BDIKAXP,OU=OLD Comps,DC=Biomed
CN=BENI-LAP,OU=OLD Comps,DC=Biomed
CN=BENIR,OU=OLD Comps,DC=Biomed
CN=BENIS-W7,OU=OLD Comps,DC=Biomed
CN=BOLGA-PC,OU=W7,OU=Metal Institute,DC=Biomed
CN=BUSDEVSTUDXP-1,OU=OLD Comps,DC=Biomed
CN=BUSDEVSTUDXP-4,OU=OLD Comps,DC=Biomed
CN=AMITUSER19,OU=AMIT Desktops,OU=AMIT,DC=Biomed
0
nesher13Author Commented:
fotech,

please ignore previous comment
------------------------------------------------------
I am run Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | select distinguishedname, name | sort distinguishedname

CN=ATL,OU=WinXPWMI,DC=Biomed
CN=ACC2,OU=AMIT Desktops,OU=AMIT,DC=tr,DC=Biomed
CN=ACC3,OU=AMIT Desktops,OU=AMIT,DC=Biomed
CN=ACC6,OU=AMIT Desktops,OU=AMIT,DC=Biomed
CN=AUTHRIZATIONMMI,OU=OLD Comps,DC=Biomed
CN=AVIAVXPSP2,OU=OLD Comps,DC=Biomed
CN=B-D_COMP1,OU=OLD Comps,DC=Biomed
CN=BDIKAXP,OU=OLD Comps,DC=Biomed
CN=BENI-LAP,OU=OLD Comps,DC=Biomed
CN=BENIR,OU=OLD Comps,DC=Biomed
CN=BENIS-W7,OU=OLD Comps,DC=Biomed
CN=BOLGA-PC,OU=W7,OU=Metal Institute,DC=Biomed
CN=BUSDEVSTUDXP-1,OU=OLD Comps,DC=Biomed
CN=BUSDEVSTUDXP-4,OU=OLD Comps,DC=Biomed
CN=AMITUSER19,OU=AMIT Desktops,OU=AMIT,DC=Biomed
0
footechCommented:
Maybe this is what you want?
Search-ADAccount -AccountInactive -TimeSpan "90" -computersOnly | Select @{n="parentOU";e={ ((($_.DistinguishedName -split "OU=")[-1]) -split ",")[0] }},Name

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nesher13Author Commented:
footech,

excellent!!!

only ignores the container Computers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.