Sample Application using Groupwise Administrative Object API


Below is a copy of the source to a C# App that connects to a domain and creates a nickname for every user in the CSV. This code can be easily modified (and was in our case) to set the LDAP Authentication field in Groupwise to enable authentication via services such as Active Directory.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace GWAdmin
{

class Program
{
[STAThread]
static void Main(string[] args)
{
StringBuilder sbLog = new StringBuilder();
StreamWriter swLog = new StreamWriter(@”C:alias-to-nickname.log”);
try
{
AdminTypeLibrary.System GWSystem = new AdminTypeLibrary.System();
string strPath = @”\fsvol1gwdomprimary”;
GWSystem.Connect(strPath);
List list = parseCSV(@”C:aliasnohead-test.csv”);

foreach (string[] strarr in list)
{

string poName = strarr[3];
string owner = strarr[4];
string nickname = strarr[1];
AdminTypeLibrary.Domain domain = GWSystem.Domains.Item(“primary”);
AdminTypeLibrary.PostOffice po = GWSystem.PostOffices.Item(poName, domain);
AdminTypeLibrary.User3 user3User = (AdminTypeLibrary.User3)po.Users.Item(owner, po, domain);
if (user3User.PrefEMailID != null)
{
user3User.PrefEMailID = null;
user3User.ClearAddressFormat();
user3User.ClearAllowedAddressFormat();
user3User.ClearInternetDomainName();
user3User.Commit();
sbLog.AppendLine(DateTime.Now + ” :: Cleared PrefEMailID from user: ” + user3User.Name);
}
else
{
sbLog.AppendLine(DateTime.Now + ” :: PrefEMailID for : ” + user3User.Name + ” was blank. Skipping…”);
}
AdminTypeLibrary.AdminObject ao = (AdminTypeLibrary.AdminObject)user3User;
GWSystem.Nicknames.Add(nickname, ao, ao.PostOffice, ao.PostOffice.Domain);
sbLog.AppendLine(DateTime.Now + ” :: Added nickname: ” + nickname + ” for owner: ” + owner);
}

}
catch (Exception ex)
{
sbLog.AppendLine(DateTime.Now + ” :: ” + ex.ToString);
swLog.WriteLine(sbLog.ToString());
}
swLog.WriteLine(sbLog.ToString());
swLog.Close();

}
public static List parseCSV(string path)
{
List parsedData = new List();

try
{
using (StreamReader readFile = new StreamReader(path))
{
string line;
string[] row;

while ((line = readFile.ReadLine()) != null)
{
row = line.Split(‘,’);
parsedData.Add(row);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

return parsedData;
}

}
}


Leave a Reply

0 thoughts on “Sample Application using Groupwise Administrative Object API