Kaspersky Security Center Automation
10.0
|
JScript sample code.
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; }; function processOU(oGroups, oAdHosts, nOU, nLevel, oFileds2Return, nGroup) { var oInfo = oAdHosts.GetChildOUs(nOU, oFileds2Return); ; var enumObj = new Enumerator(oInfo); for(; !enumObj.atEnd(); enumObj.moveNext() ) { var oObj = enumObj.item(); // OU name var strName = oObj.Item("adhst_idComputer"); var nId = oObj.Item("adhst_id"); // form indention for logging var strIndention = " "; for(ii =0; ii < nLevel; ++ii) strIndention += " "; strIndention += "+-" // log found OU g_oLog.Write(strIndention); g_oLog.WriteLine(strName); // create group for found OU var oProps = new ActiveXObject("klakaut.KlAkParams"); oProps.Add("name", strName); oProps.Add("parentId", nGroup); var nIdNewGroup = oGroups.AddGroup(oProps); // process subOUs recursively processOU(oGroups, oAdHosts, nId, nLevel+1, oFileds2Return, nIdNewGroup); }; }; var g_oFileSystemObject; var g_oLog; // prepare logging g_oFileSystemObject = new ActiveXObject("Scripting.FileSystemObject"); g_oLog = g_oFileSystemObject.CreateTextFile("log.txt", true); try { // create proxy to the Administration Server var oAdmServer = AcquireAdServerProxy(); var oGroups = new ActiveXObject("klakaut.KlAkGroups"); oGroups.AdmServer = oAdmServer; var oAdHosts = new ActiveXObject("klakaut.KlAkAdHosts"); oAdHosts.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); var oFileds2Return = new ActiveXObject("klakaut.KlAkCollection"); oFileds2Return.SetSize(3); oFileds2Return.SetAt(0, "adhst_id"); oFileds2Return.SetAt(1, "adhst_idParent"); oFileds2Return.SetAt(2, "adhst_idComputer"); processOU(oGroups, oAdHosts, 0, 0, oFileds2Return, lCreatedGroup); } catch(e) { g_oLog.WriteLine("Error " + e.number + " occured !!! " + e.description); }; g_oLog.Close();