What domain controllers are computers authenticating to?

Welcome Forums General PowerShell Q&A What domain controllers are computers authenticating to?

This topic contains 5 replies, has 4 voices, and was last updated by

Jon
 
Participant
1 year, 3 months ago.

  • Author
    Posts
  • #76153

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 144
    Helping Hand
    Rank: Participant

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

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

    Participant
    Points: 0
    Rank: Member

    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

      Participant
      Points: 144
      Helping Hand
      Rank: Participant

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

    • #76237

      Participant
      Points: 0
      Rank: Member

      Olaf,

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

  • #76339
    Jon

    Participant
    Points: 24
    Rank: Member

    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}

The topic ‘What domain controllers are computers authenticating to?’ is closed to new replies.