What domain controllers are computers authenticating to?

This topic contains 5 replies, has 4 voices, and was last updated by  Jon 2 months, 3 weeks ago.

  • Author
    Posts
  • #76153

    Kano
    Participant

    I am trying to write script below that will list the domain controller all computers in an OU are using for authentication and export the data to a file. Scripting is not my wheelhouse so I thought I would enlist some assistance.

    Get-ADComputer -filter * -searchbase "OU=yourcomputerOU,DC=domain,DC=com" | %{(Get-WmiObject -Class win32_ntdomain -Filter "DomainName = 'mydomain'" -ComputerName $_.Name).DomainControllerName}

    Thanks,
    Kano

  • #76162

    Olaf Soyk
    Participant

    Hmmm ... why to make the life harder than needed?

    Get-ADDomainController -Filter * | Select-Object -Property Name
  • #76172

    Richard Siddaway
    Moderator

    Get-ADDomainController -filter * will return all domain controllers based on the machine used. It won't return the authenticating DC for a remote machine. You'd also need to have the AD cmdlets on all machines to be able to use that approach

    • #76174

      Olaf Soyk
      Participant

      Ahh ... now I actually understood what the question was about. Sorry, I got this wrong.

    • #76237

      Kano
      Participant

      Olaf,

      Do I insert your script at the beginning of my mine and leave the remaining scrip as is?

  • #76339

    Jon
    Participant

    You could use $env:logonserver variable

    Something like this maybe (I have not tested it)

    Invoke-Command -ComputerName (Get-ADComputer -filter * -searchbase "OU=yourcomputerOU,DC=domain,DC=com") -scriptblock {$env:logonserver}

    or get the computer names in a text file and do this

    Invoke-Command -ComputerName (gc C:\computers.txt) -scriptblock {$env:logonserver}

You must be logged in to reply to this topic.