I'm looking for a way to obtain the OU information of a computer from its local WMI or Registry. I know there are ways to pull the OU information from a host using PowerShell and AD commandlets... Afraid every time we execute the commands, it will hit the domain controller and pull the information. If we run similar commands simultaneously on a large number of computers, it would spike the number of connections to Domain Controllers. We would like to avoid such cases and see if we can find a way to obtain the OU information if it's stored locally in the host.
I did find a few sample codes from other responses and they are working well, however, I feel they are retrieving the information from Domain Controller (sorry if I misunderstood). Could someone confirm if this is the only option we have to use or is there any alternative solution?
Sample Code:
([adsisearcher]"(&(name=$env:computername)(objectClass=computer))").findall().path
(or)
Import-Module ActiveDirectory -Force;
Get-ADComputer $env:computername | select -ExpandProperty DistinguishedName
Thanks, Nana