Finding Domain Controllers

I am always amazed how often I find code that assumes that a particular circumstance will be true. Someone will hardcode a script to refer to a primary domain controller (PDC), for example. It is possible for a primary domain controller to go down and a backup domain controller (BDC) to automatically step in and act as a temporary PDC, or an administrator can manually promote a BDC to take over the role of the PDC. (If this occurs, the PDC steps down and acts as a BDC.) Because of this, it is a bad idea to hardcode a PDC’s computer name into a script. You should instead resolve the name of the domain’s PDC using the GetDomainController() function:

 Win32::NetAdmin::GetDomainController($Server, $Domain, $Name); Win32::Lanman::NetGetDCName($Server, ...

Get Win32 Perl Programming: The Standard Extensions, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.