📜  PS 获取 DC 控制器 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:23.305000             🧑  作者: Mango

代码示例1
$domain = [System.Directoryservices.Activedirectory.Domain]::GetCurrentDomain()
$domain | ForEach-Object {$_.DomainControllers} | 
ForEach-Object {
  $hostEntry= [System.Net.Dns]::GetHostByName($_.Name)
New-Object -TypeName PSObject -Property @{
      Name = $_.Name
      IPAddress = $hostEntry.AddressList[0].IPAddressToString
    }
} | Select Name, IPAddress