Author Posts

July 28, 2017 at 8:38 pm

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

July 29, 2017 at 12:32 am

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

Get-ADDomainController -Filter * | Select-Object -Property Name

July 29, 2017 at 4:15 pm

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

July 29, 2017 at 5:53 pm

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

July 31, 2017 at 12:49 pm

Olaf,

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

August 1, 2017 at 11:47 am

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}