Kaspersky Security Center Automation  10.0
Sample. Creating group structure based on AD organization units structure.

JScript sample code.

var g_strDefaultNamingContext;
var g_oFileSystemObject;
var g_oLog;

function AcquireAdServerProxy()
{ 
	var oSrvConnectionProps = new ActiveXObject("klakaut.KlAkParams");
	oSrvConnectionProps.Add("Address", "localhost:13000");
	oSrvConnectionProps.Add("UseSSL", true);

	var oAdmServer = new ActiveXObject("klakaut.KlAkProxy");
	oAdmServer.Connect(oSrvConnectionProps);
	g_oLog.WriteLine("Server version is " + oAdmServer.VersionId);
	return oAdmServer;
};

// returns default AD naming context
function GetDefaultNamingContext()
{
	var oRootDSE = GetObject("LDAP://RootDSE"); 
	var strDefaultNamingContext = oRootDSE.Get("defaultNamingContext");
	g_oLog.WriteLine("DefaultNamingContext is " + strDefaultNamingContext);
	return strDefaultNamingContext;
};

function processOU(oProxy, nGroup, oCom, oDn, nLevel)
{
	// set query string for command object
	oCom.CommandText = "<LDAP://" + oDn + ">;(&(objectCategory=organizationalUnit)(|(!(showInAdvancedViewOnly=*))(showInAdvancedViewOnly=0)));name, distinguishedName;oneLevel";
	var oRs = oCommand.Execute();

	// process returned recordset
	for(; !oRs.EOF; oRs.MoveNext())
	{
	 // OU name
	 var oNewName = oRs.Fields("name");

	 // OU distinguished name
	 var oNewDN = oRs.Fields("distinguishedName");

	 // form indention for logging
	 var strIndention = "	";
	 for(ii =0; ii < nLevel; ++ii)
		 strIndention += "  ";
	 strIndention += "+-"

	 // log found OU
	 g_oLog.Write(strIndention);
	 g_oLog.WriteLine(oNewName);

	 // create group for found OU
	 var oProps = new ActiveXObject("klakaut.KlAkParams");
	 oProps.Add("name", oNewName + ""); //force 'string' datatype
	 oProps.Add("parentId", nGroup);
	 var nIdNewGroup = oGroups.AddGroup(oProps);

	 // process subOUs recursively
	 processOU(oProxy, nIdNewGroup, oCom, oNewDN, nLevel+1);
};
};



//Start execution

// prepare logging
g_oFileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
g_oLog = g_oFileSystemObject.CreateTextFile("log.txt", true);

try {
	g_strDefaultNamingContext = GetDefaultNamingContext();

	// prepare connection to AD
	oConnection = new ActiveXObject("ADODB.Connection");
	oConnection.Provider = "ADsDSOObject";
	oConnection.Open("Active Directory Provider");

	// prepare command object
	oCommand = new ActiveXObject("ADODB.Command");
	oCommand.ActiveConnection = oConnection;

	// create proxy to the Administration Server
	var oAdmServer = AcquireAdServerProxy();

	var oGroups = new ActiveXObject("klakaut.KlAkGroups");
	oGroups.AdmServer = oAdmServer;

	var strGroupName = "TestGroup";

	// create new group
	var oProps = new ActiveXObject("klakaut.KlAkParams");
	oProps.Add("name", strGroupName);
	oProps.Add("parentId", oGroups.GroupIdGroups);
	var lCreatedGroup = oGroups.AddGroup(oProps);


	// process organisation units
	g_oLog.WriteLine("Processing organization units");
	processOU(oGroups, lCreatedGroup, oCommand, g_strDefaultNamingContext, 1);
}
catch(e)
{
	g_oLog.WriteLine("Error " + e.number + " occured !!! " + e.description);
};


g_oLog.Close();