Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Thursday, October 6, 2011

Determine which Domain Controller a client is connected to with PowerShell

When a Windows client comes online, it must find a domain controller to bind to.  Either through a static configuration or DHCP, the client will request a list of all Domain Controllers in the domain from a DNS server.  Once the list is received, the client will randomly go through the list to find a DC that will respond.  Once the client has authenticated itself with the DC, the DC will transmit the site information to the client.  The site information will contain the site name, the subnet(s) associated with that site, and any domain controllers in that site.  The client will then take a look at it’s own IP address to determine which site it is in.  From the list of DCs in the same site, it will attempt to bind to one of those DCs to receive it’s Group Policies.

 

You can use PowerShell and WMI to locate the domain controller that a client is connected to.

 

Get-WMIObject Win32_NTDomain

 

Look for the DomainControllerName property.

 

image

3 comments:

therook711 said...

I really appreciate this as the simple "set" command doesn't work in Windows 2012.

Geert said...

This is an old topic but just a reminder to therook: set command does work, just not in a PS command prompt, type cmd in a ps prompt and you will be able to use set l

Jason Yoder, MCT said...

Yes, SET does work in DOS mode. The difference is that SET does not produce an object. This makes it harder for us to use. The PowerShell method formats the data in a way that allows us to continue to use it in the pipeline.