Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







List all objects in a domain

Posted by on Friday, January 16, 2004 (PST)

listem 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 ); }

Add Your Comment



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


  • Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon