【发布时间】:2023-03-30 13:44:01
【问题描述】:
我搬到了一家拥有旧服务器且没有 RSAT 的公司,因此我无法使用 AD 模块,并且必须确保脚本符合 v2。
我已经编写了一个发现脚本来查找森林中的所有域,并且我正在尝试将其通过管道传输到另一个脚本中,以找出我也可以访问的域中计算机的所有 dns 主机名,但不断收到各种错误。
森林代码中的域:
$Root = [ADSI]"LDAP://RootDSE"
$oForestConfig = $Root.Get("configurationNamingContext")
$oSearchRoot = [ADSI]("LDAP://CN=Partitions," + $oForestConfig)
$AdSearcher = [adsisearcher]"(&(objectcategory=crossref) (netbiosname=*))"
$AdSearcher.SearchRoot = $oSearchRoot
$Domains = $AdSearcher.FindAll()
return $Domains|$Domains = "dc=" + $Domains.Name.Replace(".", ",dc=") |Out-File C:\domains.txt
查找 dns 主机名的代码:
$doms = Get-Content C:\domains.txt
foreach ($dom in $doms) {
$AD = (([adsisearcher]"").Searchroot.path)
IF ($AD -notlike "LDAP://*") {$AD ="LDAP://$AD"}
$AD.Filter = "(&(objectCategory=Computer)(name=$item))"
$Computers = $AD.Filter.FindAll()
$ComputerNames = $Computers.Properties.dnshostname
}
有什么想法吗?
【问题讨论】:
-
$item应该在你的$AD.Filter语句中是什么? -
这个
keep getting various errors几乎毫无意义。请将您的错误测试添加到您的问题中 - 格式化为代码,以便于阅读。
标签: powershell active-directory powershell-2.0