I'm using WMI and am trying to find a powershell script that will allow me get the OU of the local computer and then get a full list of computers in that OU.
How do I use WMI to get the current OU of a computer and list all other computers in that OU?
22.9k views Asked by user2369812 At
1
There are 1 answers
Related Questions in POWERSHELL
- No responses from google places text search api
- compare python requests with curl
- file_get_contents not working on my server but works fine anywhere else?
- Converting curl command to iOS
- cURL PHP code redirect after success
- curl command cannot get contents from api.github, but the network is fine
- PHP cURL Request for Web Service Returning Error
- How to convert CURL command to Swift
- curl command don't work in some cases
- Silence output curl_setopt_array
Related Questions in ACTIVE-DIRECTORY
- No responses from google places text search api
- compare python requests with curl
- file_get_contents not working on my server but works fine anywhere else?
- Converting curl command to iOS
- cURL PHP code redirect after success
- curl command cannot get contents from api.github, but the network is fine
- PHP cURL Request for Web Service Returning Error
- How to convert CURL command to Swift
- curl command don't work in some cases
- Silence output curl_setopt_array
Related Questions in WMI
- No responses from google places text search api
- compare python requests with curl
- file_get_contents not working on my server but works fine anywhere else?
- Converting curl command to iOS
- cURL PHP code redirect after success
- curl command cannot get contents from api.github, but the network is fine
- PHP cURL Request for Web Service Returning Error
- How to convert CURL command to Swift
- curl command don't work in some cases
- Silence output curl_setopt_array
Related Questions in OU
- No responses from google places text search api
- compare python requests with curl
- file_get_contents not working on my server but works fine anywhere else?
- Converting curl command to iOS
- cURL PHP code redirect after success
- curl command cannot get contents from api.github, but the network is fine
- PHP cURL Request for Web Service Returning Error
- How to convert CURL command to Swift
- curl command don't work in some cases
- Silence output curl_setopt_array
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Here you go:
I think this also finds computers in child OUs, but I'm not sure how to limit it to a single OU without doing a ton of queries. The query syntax is just rather sparse. Eliminating the child OU objects after retrieval of the full list might be the only way to do it with any semblance of performance.
Fair warning: This is slow. Really slow. Like "Oh, crap did I break something?!" slow. I pointed it at a computer that shares an OU with less than 20 other computers, and it takes nearly a minute to run. Even the first fetching of just the single computer takes more than 1 second.
Here's what I would recommend:
That takes 2 seconds, including loading the Active Directory module. With it already loaded, that takes less than 200 milliseconds.
If you don't have access to the
ActiveDirectory
PowerShell module, then you can use an[ADSISearcher]
. These are also a pain to use because of how results are presented, but they're even faster than theActiveDirectory
module, which is basically just a wrapper for this.This runs in about 50 milliseconds.
However, beware that the ADSI system is known to contain memory leaks if it's not called correctly or if
FindAll()
is called and the results are never used. I myself have created objects with this method and then not disposed of them and left my shell process open overnight, and when I came in the next morning my system was all but unresponsive because all the memory had been consumed. TheActiveDirectory
module avoids these problems entirely, and is even more code light, so unless you really need those extra few milliseconds than I would favor that module.