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 best solutions below
Related Questions in POWERSHELL
- How to ignore warning errors?
- Data execution plan ended with error on DB restore
- Powershell Split a file name
- PowerShell EWS Save as for e-mails
- Run SQL Server Update Statement With Powershell
- using a global variable in multiple functions powershell
- Heisenberg was here: Aliases for PowerShell parameters only appear in cmdlet help when you do NOT document the cmdlet
- PowerShell Script to add newuser
- Why is PowerShell "not recognized" when installing Chocolatey?
- Enumerate a PSCustomObject as key/value pairs
- Unable to start program outside Windows folder
- Ask for creds only if some specified
- PowerShell 3 Parameters
- i can't ping a computer but remoting into it works (powershell enter-pssession)
- Feeding Variables in new-aduser -path option in powershell
Related Questions in ACTIVE-DIRECTORY
- PowerShell Script to add newuser
- Active directory and linux nslcd binding without extending the AD schema
- Retrieve user information from Active Directory on login
- Feeding Variables in new-aduser -path option in powershell
- Log in through active directory
- Swapping attributes in AD
- How to get LastLogon from ALL Domain Controllers
- Getting LastLogon and LastLogonTimeStamp from ALL Domain Controllers into 1 output CSV
- Spring LDAP Context.REFERRAL to follow
- Avoiding Active Directory Uniqueness Constraint Violation During Rename
- samba retrieving users with arbitrary attributes
- WinApi and work with several domains
- Tomcat LDAP User Auth
- how to add multiple Owner in ADLDS groups
- Zend Framework Active Directory authentication
Related Questions in WMI
- How to determine which Windows drives map to which SAN storage devices using WMI?
- Get all visualsvn permissions for particular (user)SID from python WMI
- Facing error "System.IO.FileNotFoundException:"
- Getting access denied when trying to extract system information using a asp.net web application
- Calling a method of a WMI Class
- Invoking a method thtough C#
- How to collect windows performance counter data (WMI) using Logstash forwarder
- How to check if every users on the system has administrator rights in C#
- WMI query for Counter of type RateOfCountsPerSecond32 shows raw value instead of persecond value
- How to access hidden partitions/volumes
- Why can't local Windows 7 Pro machine read its own WMI values?
- Setting Size of String Buffer When Accessing Windows Registry
- How do I retrieve a list of primary users of computers
- wmi SetSecurityDescriptor
- Where is wmi hpqBIntM provider dll located?
Related Questions in OU
- Organizing Active Directory accounts
- Multiple Organizational Units (OU) ASN.1 encoding differences
- Get OU (Organizational Unit) name that a local computer belongs to using C++
- How do I use WMI to get the current OU of a computer and list all other computers in that OU?
- Create a CSR with OU separated by comma instead of plus character
- How to query Organizational Units from a given DN in Perl
- What is the difference between an AWS IAM Group and an Organizational Unit?
- php AD ldap search filter specific OUS
- How do I remove all the groups from disabled Active Directory Users via Powershell?
- delegate 'Create all child objects' permission in OU
- How can I find what Organizational Units a computer is part of? ( Active Directory C# )
- check if OU is protected from accidental deletion
- How to join a workgroup computer to a domain remotely
- Copy AD attributes (state to city) in a specific OU
- VBS Scripting to move computers from one OU to the next
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)
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?
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
ActiveDirectoryPowerShell 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 theActiveDirectorymodule, 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. TheActiveDirectorymodule 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.