简体   繁体   中英

How to find computer object OU from server itself using CMD

How can I find what OU the computer belongs to using CMD or powershell cmdlet . I have found some long scripts but there has to be a one liner command for it. The computers dont have AD role installed on them so DSQUERY is out of equation. CMD or powershell cmdlet would work.

A one-liner for PowerShell without AD Role would be:

([adsisearcher]"(&(name=$env:computername)(objectClass=computer))").findall().path

That would give you a string like:

LDAP://CN=MyComputer,OU=Workstations,OU=Machines,DC=TacoTruck,DC=com

That would work on the local computer. If you want to run against a remote server on the same domain replace $env:computername with the name of the computer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM