d

FSMO Roles

/** 
 *    Script:   FSMORoles.js 
 *    Purpose:  Lists owners of the 5 FSMO Roles. 
 *    Author:   Daren Thiel  
 *    Date:     20 Mar 2004  
 *    Web:      http://www.winscripter.com 
 *    Note:     Must be ran in AD environment with sufficient 
 *              permission to query LDAP 
 **/
GetFSMORoles();
function GetFSMORoles()
{ 
    try 
    {  
        print( "FSMO Roles" );  
        print( "=====================================" );    
        //////////////////////////////////////////  
        // Find the correct context for this env  
        //////////////////////////////////////////  
        var rootdse = GetObject( "LDAP://rootDSE" );  
        var DNC = rootdse.Get( "defaultNamingContext" );  
        var SNC = rootdse.Get( "schemaNamingContext" );  
        var CNC = rootdse.Get( "configurationNamingContext" );
        
        //////////////////////////////////////////  
        // schema master  
        //////////////////////////////////////////  
        var oschema = GetObject( "LDAP://" + SNC );  
        var sSchemaMaster = oschema.Get( "fSMORoleOwner" );  
        var oNTDS = GetObject( "LDAP://" + sSchemaMaster );  
        var oComp = GetObject( oNTDS.Parent );  
        print( "Schema Master         : " + oComp.Name );    
        
        //////////////////////////////////////////  
        // Domain Naming Master  
        //////////////////////////////////////////  
        var oPart = GetObject( "LDAP://CN=Partitions," + CNC );  
        var sDomainNamingMaster = oPart.Get( "fSMORoleOwner" );  
        oNTDS = GetObject( "LDAP://" + sDomainNamingMaster );  
        oComp = GetObject( oNTDS.Parent );  
        print( "Domain Naming Master  : " + oComp.Name );    
        
        //////////////////////////////////////////  
        // PDC Emulator  
        //////////////////////////////////////////  
        var oDomain = GetObject( "LDAP://" + DNC );  
        var sPDCEm  = oDomain.Get( "fSMORoleOwner" );  
        oNTDS = GetObject( "LDAP://" + sPDCEm );  
        oComp = GetObject( oNTDS.Parent );  
        print( "PDC Emulator          : " + oComp.Name );    
        
        //////////////////////////////////////////  
        // RID  
        //////////////////////////////////////////  
        var oRID = GetObject( "LDAP://CN=RID Manager$,CN=System," + DNC  );  
        var oRIDMaster  = oRID.Get( "fSMORoleOwner" );  
        oNTDS = GetObject( "LDAP://" + oRIDMaster );  
        oComp = GetObject( oNTDS.Parent );  
        print( "RID Master            : " + oComp.Name );
  
        //////////////////////////////////////////  
        // Infrastructure  
        //////////////////////////////////////////  
        var oInfra = GetObject( "LDAP://CN=Infrastructure," + DNC );  
        var oInfraMaster = oInfra.Get( "fSMORoleOwner" );  
        oNTDS = GetObject( "LDAP://" + oInfraMaster );  
        oComp = GetObject( oNTDS.Parent );  
        print( "Infrastructure Master : " + oComp.Name ); 
    } 
    catch( e ) 
    {  
        print( "Error: " + e.description );   
    }
}

function print( msg )
{ 
    WScript.Echo( msg );
}