Hello, as you all know sometimes PCs end up in the wrong OU
We have a few to choose from and this is how my domain is setup
Company.net
Computers
Managed Computers
East Coast
West Coast
Test
Pilot
I'd like to populate just East Coast and West Coast in my context menu
Using ADSI is much quicker than cmdlets
So essentialy be able to move a computer to the correct OU with a few clicks.
I've searched the web and cannot seem to find how to find and filter this specific
Listing specific OUs for context menu
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.
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.
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
What is it that you do not know how to do?
What is it you are trying to filter? You need to refine your requirements to something much more detailed before you can turn it into code.
What is it you are trying to filter? You need to refine your requirements to something much more detailed before you can turn it into code.
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
Hi, sorry about that.
I'm trying to list specific OU's. Lets start with that. As you can see there are several OUs
The results I do not want to return are:
NYC, Miami, Las Vegas, Seattle, Pilot and Test
I'm trying to list specific OU's. Lets start with that. As you can see there are several OUs
The results I do not want to return are:
NYC, Miami, Las Vegas, Seattle, Pilot and Test
Re: Listing specific OUs for context menu
Then you need to filter them out of the results. You can use a "Where-Object"
... Where-Object{ $computer.DistinguishedName -notmatch 'NYC|Miami|Las Vegas|Seattle|Pilot|Test' }
... Where-Object{ $computer.DistinguishedName -notmatch 'NYC|Miami|Las Vegas|Seattle|Pilot|Test' }
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
I need the ADSI part to list the OUs
That’s where I’m stuck now, I’ve searched the web but I’m unable to find an example I can work from
I think once I get that figured out, the rest should come together for me.
Your .... in the previous post is the part I’m missing.
I apologize for the inconvenience.
That’s where I’m stuck now, I’ve searched the web but I’m unable to find an example I can work from
I think once I get that figured out, the rest should come together for me.
Your .... in the previous post is the part I’m missing.
I apologize for the inconvenience.
Re: Listing specific OUs for context menu
I thought you wanted the computers? If you know the OUs then just add them by name to the listbox.
Get all computers and filter them.
Your intent is too vague without a clear statement of use case and workflow.
To get all computers just do this:
([adsisearcher]'objectclass=computer').FindAll()
Now just filter that.
Get all computers and filter them.
Your intent is too vague without a clear statement of use case and workflow.
To get all computers just do this:
([adsisearcher]'objectclass=computer').FindAll()
Now just filter that.
Re: Listing specific OUs for context menu
Here is a small demo of how to use ADSI:
Code: Select all
([adsisearcher]'objectclass=computer').FindAll() |
Where{$_.Path -notmatch 'Domain Controllers'} |
ForEach{[adsi]$_.Path} |
select name,parent
Re: Listing specific OUs for context menu
Filter OUs by name:
Code: Select all
([adsisearcher]'objectclass=organizationalunit').FindAll() |
Where{$_.Path -notmatch 'Domain Controllers|Terminated|TestOU.*'}