繁体   English   中英

如何在Powershell中查询多个域的计算机帐户

[英]how can I query to multiple domain's computer account in powershell

我的CSV文件中包含带有服务器标头的批量计算机列表。

所有这些服务器都是单个林中的不同域。

我需要获取所有这些服务器属性的详细信息,例如名称和操作系统,状态。

我已经创建了下面的脚本,但是没有用。

任何帮助,将不胜感激。

Import-Module ActiveDirectory

# For each domain in the forest

$domains = (Get-ADForest).Domains
$servers = Import-Csv "D:\temp\computer.csv" | % {$_.server}

foreach ($server in $servers)
{
  foreach ($domain in $domains)
  {
    Get-ADComputer $server -Server $domain -Properties operatingsystem | select name,operatingsystem 
  }
}

我添加了如下脚本:

 Import-Module ActiveDirectory # For each domain in the forest $domains = (Get-ADForest).Domains $servers = Import-Csv "D:\\temp\\computers.csv" | % {$_.server} $DomainController = "DC2:3268" # 3268 is the commen port of global catalogue $SearchBase = ((Get-ADDomain (Get-ADForest).RootDomain).DistinguishedName) foreach ($server in $servers) { foreach ($domain in $domains) { Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem } } 

现在出现以下错误,并且这次我仅指定了计算机的samaccountname而不是FQDS。

####错误
 Get-ADComputer : A positional parameter cannot be found that accepts argument 'DPS002'. At D:\\temp\\search_computer.ps1:34 char:5 + Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Pr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADComputer 

您必须对全局目录运行请求才能在整个AD林中查找AD对象。

  1. 您需要服务器支持全局编录。 选择您旁边的一个。

     Import-Module ActiveDirectory @((Get-ADForest).GlobalCatalogs) | Sort-Object 
  2. 您的脚本,做了一些修改

     Import-Module ActiveDirectory $DomainController = "ServerFromStep1:3268" # 3268 is the commen port of global catalogue $SearchBase = ((Get-ADDomain (Get-ADForest).RootDomain).DistinguishedName) foreach ($server in $servers) { Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem } 
  3. 与2相同,但能够处理服务器列表中的FQDN

     foreach ($serverFQDN in $servers) { $Local:ServerName = (($serverFQDN -replace "\\..*$", "").Trim()) if ($ServerName) { Get-ADComputer $ServerName -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem } } 

暂无
暂无

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

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