我有一个拥有许多AD域的大森林,并经常添加新的域名。 我需要这些广告域的列表来查询每个DC。
GetAllTrustRelationships()不是枚举林中所有域的非常安全的方法,也可能包含其他林/域。
而是从Forest对象中获取Domains引用:
function Get-ADInside { $Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() $Domains = $Forest.Domains $Domains |Select -ExpandProperty Name }
这个函数列出你在林中可用的Active Directory域(包括当前域=> $ Forest.Domains.name)
function get-AdInside () { $MainForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() $ForestTrusts = $MainForest.GetAllTrustRelationships() $ADs = @($MainForest.Domains.name) $ADs += $ForestTrusts.TargetName return $ADs }
用当前域2008-2008r2-2012 +进行testing