I've had several requests for this script since mentioning in passing a
while back. It's short enough to post to the list.
It creates a batch file that uses LDAPer to restore the LDAP info. If the
imail LDAP database gets hosed, just do an "Init LDAP" from iAdmin, then run
the most recent backup file created by the script.
I stripped out the parts that required wsh 5.6 (command line args), should
work with any version of wsh.
Change values of SpoolDir and LDAPHost appropriately.
This is unsupported, use at your own risk, etc.
Jerry
/*
Reads LDAP Server and creates a "backup" in the form of a batch file
that runs LDAPer.exe utility to repopulate the LDAP database.
Must use cscript.exe, not wscript.exe. Comment out the "WScript.Echo(s)"
at
end of code to use wscript.exe.
Uses LDAP control from http://www.polonia-online.com/ldap
*/
var SpoolDir = 'c:\\' //Include Trailing slash
var LDAPHost = '10.1.1.10' //Can be DNS resolvable name
var OutExtension = '.txt' //Not using .bat to avoid accidental execution
//Generate File Name
var ForReading = 1;
var OutFile
var d = new Date();
var thismonth = '' + (d.getMonth() + 1)
var thisdate = '' + d.getDate()
var thishour = '' + d.getHours()
if (thismonth.length == 1) {
thismonth = '0' + thismonth;
}
if (thisdate.length == 1) {
thisdate = '0' + thisdate;
}
if (thishour.length == 1) {
thishour = '0' + thishour;
}
OutFile = SpoolDir + 'ldap.' + LDAPHost + '.' + d.getYear() + thismonth +
thisdate + thishour + OutExtension
//Initialize LDAP objects
var pLDAP = new ActiveXObject('LDAPClient.2')
var pAttributeNames = new ActiveXObject('LDAPClient.StringCollection')
pLDAP.Connect(LDAPHost)
pAttributeNames.Add('UID')
pAttributeNames.Add('GivenName')
pAttributeNames.Add('sn')
pAttributeNames.Add('Organization')
pAttributeNames.Add('OrganizationalUnit')
pAttributeNames.Add('Street')
pAttributeNames.Add('City')
pAttributeNames.Add('State')
pAttributeNames.Add('ZipCode')
pAttributeNames.Add('Telephone')
pAttributeNames.Add('Country')
pAttributeNames.Add('Mail')
pAttributeNames.Add('CommonName')
pAttributeNames.Add('Host')
//Run Query - Write File
var DomainName, DNTemp
var pEntries, pEntry, pEnum
var s
var fso = new ActiveXObject('Scripting.FileSystemObject');
var f1 = fso.CreateTextFile(OutFile, true);
pEntries = pLDAP.Search('objectclass=' + '"person"', '(|(UID=*))', 1 ,
pAttributeNames);
pEnum = new Enumerator(pEntries)
for (;!pEnum.atEnd();pEnum.moveNext()) {
pEntry = pEnum.item();
/* "DomainName" doesn't seem to be returned by iMail
Following is ugly, but works, and I don't have time to
debug further
*/
DNTemp = pEntry.dn;
DomainName = DNTemp.split('DomainName=');
s = 'ldaper -H ' + DomainName[1] + ' ' +
'-U "' + pEntry.Attributes('UID').Values(0).Value
+ '" ' +
'-GN "' + pEntry.Attributes('GivenName').Values(0).Value
+ '" ' +
'-SN "' + pEntry.Attributes('sn').Values(0).Value
+ '" ' +
'-O "' + pEntry.Attributes('Organization').Values(0).Value
+ '" ' +
'-OU "' +
pEntry.Attributes('OrganizationalUnit').Values(0).Value + '" ' +
'-S "' + pEntry.Attributes('Street').Values(0).Value
+ '" ' +
'-C "' + pEntry.Attributes('City').Values(0).Value
+ '" ' +
'-ST "' + pEntry.Attributes('State').Values(0).Value
+ '" ' +
'-Z "' + pEntry.Attributes('ZipCode').Values(0).Value
+ '" ' +
'-T "' + pEntry.Attributes('Telephone').Values(0).Value
+ '" ' +
'-CO "' + pEntry.Attributes('Country').Values(0).Value
+ '"';
WScript.Echo(s);
f1.WriteLine(s);
}
Please visit http://www.ipswitch.com/support/mailing-lists.html
to be removed from this list.
An Archive of this list is available at:
http://www.mail-archive.com/imail_forum%40list.ipswitch.com/