Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 什么';从层次结构中的任何域(如树域或子域)获取顶级域(根域)的API是什么?_Powershell_Adsi - Fatal编程技术网

Powershell 什么';从层次结构中的任何域(如树域或子域)获取顶级域(根域)的API是什么?

Powershell 什么';从层次结构中的任何域(如树域或子域)获取顶级域(根域)的API是什么?,powershell,adsi,Powershell,Adsi,从层次结构中的任何域(如树域或子域)获取顶级域(根域)的API是什么 我能找到的最近的是GetForest或GetCurrentForest,但这不是我要找的 提前感谢,, -SunMan要从外部域名获取其林根域,请先使用,然后通过林属性获取根域对象: $ForeignDomainDNS = 'other.domain.tld' $ForeignDomainCtx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryC

从层次结构中的任何域(如树域或子域)获取顶级域(根域)的API是什么

我能找到的最近的是
GetForest
GetCurrentForest
,但这不是我要找的

提前感谢,,
-SunMan

要从外部域名获取其林根域,请先使用,然后通过
属性获取根域对象:

$ForeignDomainDNS = 'other.domain.tld'
$ForeignDomainCtx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext 'Domain',$ForeignDomain
$ForeignDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($ForeignDomainCtx)
$ForeignRootDomain = $ForeignDomain.Forest.RootDomain

$ForeignRootDomain
现在包含表示外域林的根域的
Domain
对象“[…]这不是我要找的”—您能详细说明一下吗?
GetCurrentForest()
返回的信息如何不满足您的要求?当然。。该脚本由林a的用户运行以查找林B。GetCurrentForest()获取当前用户上下文(登录者)的林对象,从而每次都发现林a。很好。。我现在明白了逻辑,它起作用了。谢谢@Mathias