d

List Objects in a Domain

List'em all

/**
 *    Script:   enumdomain.js
 *    Purpose:  Lists object in domain.
 *    Author:   Daren Thiel 
 *    Date:     9 Dec 2000 
 *    Web:      http://www.winscripter.com
 **/

var provider, oDomain, oSchema;
main();

/////////////////////////////////////////////
//         Main                            //
/////////////////////////////////////////////
function main()
{
  getCommandLine();
  try
  {
    provider = GetObject( "WinNT:" );
    oDomain = provider.openDSObject( "WinNT://" + domain, user, pass, 1 );
    if( !oDomain )
    {
      print( "unable to open DS Object" );
      WScript.Quit( 0 );
    }
    oSchema = oDomain.GetObject( "Schema", "Schema" );
  }
  catch( e )
  {
    print( "Unable to connect to " + domain + " please check name and password" );
    WScript.Quit( 0 );
  }
    
  print( "Domain: " + oDomain.Name );
  EnumCont( oDomain, " | " );
}

/////////////////////////////////////////////
//    Enumerate Container - Recursive      //
/////////////////////////////////////////////
function EnumCont( oParent, stPad )
{
  try
  {
    var children = new Enumerator( oParent );
    for( ; !children.atEnd(); children.moveNext() )
    {
      var child = children.item();
      if( child.Class != "Schema" )
      {
        print( stPad + padx( child.Name, 50 ) + "  [" + child.Class + "]" );
        
        var oClass = oSchema.GetObject( "Class", child.Class );
        if( oClass.Container )
          EnumCont( child, stPad + "  |-- " );
      }
    }
  }
  catch( e )
  {
    print( "Error: " + e.description );
  }
}

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

/////////////////////////////////////////////
//              Padx                       //
/////////////////////////////////////////////
function padx( msg, size )
{
  var smsg = String( msg );
  while( smsg.length < size )
    smsg += " ";

  return( smsg );
}

/////////////////////////////////////////////
//          getCommandLine                 //
/////////////////////////////////////////////   
function getCommandLine()
{
  var args = WScript.Arguments;
  if( args.length < 3 )
    showUsage();
  else
  {
    domain = args( 0 );
    user   = args( 1 );
    pass   = args( 2 );
  }
}

/////////////////////////////////////////////
//              Show Usage                 //
/////////////////////////////////////////////
function showUsage()
{
  print( "usage: cscript.exe " + WScript.ScriptName + " <domain> <user> <pass>" );
  WScript.Quit( 0 );
}