简体   繁体   English

如何使用CMD从服务器本身查找计算机对象OU

[英]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 . 如何使用CMD或powershell cmdlet查找计算机所属的OU。 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. 这些计算机没有安装AD角色,因此DSQUERY不合理。 CMD or powershell cmdlet would work. CMD或powershell cmdlet将起作用。

A one-liner for PowerShell without AD Role would be: 没有AD角色的PowerShell的单行代码是:

([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. 如果要在同一域上的远程服务器上运行,请将$env:computername替换$env:computername名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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