Find FSMOs (Perl)

This code can be found in Chapter 3 of Active Directory Cookbook, 2nd edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# This Perl code prints the FSMO role owners for the specified domain.

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Active Directory Cookbook" by Robbie Allen
# Publisher: O'Reilly and Associates
# ISBN: 0-596-00466-4
# Book web site: http://rallenhome.com/books/adcookbook/code.html
# ---------------------------------------------------------------

# ------ SCRIPT CONFIGURATION ------
my $strDomain = "<DomainDNSName>";  # e.g. emea.rallencorp.com
# ------ END CONFIGURATION ---------
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $objRootDSE = Win32::OLE->GetObject("LDAP://$strDomain/RootDSE");
my $strDomainDN  = $objRootDSE->Get("defaultNamingContext");
my $strSchemaDN = $objRootDSE->Get("schemaNamingContext");
my $strConfigDN = $objRootDSE->Get("configurationNamingContext");

# PDC Emulator
my $objPDCFsmo = Win32::OLE->GetObject("LDAP://" . $strDomainDN);
print "PDC Emulator: ", $objPDCFsmo->fsmoroleowner,"\n";

# RID Master
my $objRIDFsmo = Win32::OLE->GetObject("LDAP://cn=RID Manager\$,cn=system,$strDomainDN");
print "RID Master: ", $objRIDFsmo->fsmoroleowner, "\n";

# Schema Master
my $objSchemaFsmo = Win32::OLE->GetObject("LDAP://" . $strSchemaDN);
print "Schema Master: ", $objSchemaFsmo->fsmoroleowner,"\n";

# Infrastructure Master
my $objInfraFsmo = Win32::OLE->GetObject("LDAP://cn=Infrastructure," . $strDomainDN);
print "Infra$structure Master: ", $objInfraFsmo->fsmoroleowner,"\n";

# Domain Naming Master
my $objDNFsmo = Win32::OLE->GetObject("LDAP://cn=Partitions," . $strConfigDN);
print "Domain Naming Master: ", $objDNFsmo->fsmoroleowner,"\n";

This code has been viewed 1439 times.

New from the creators of TechTasks.com: StatSheet.com