Saturday, October 10, 2009

How to enter multiple users into ActiveDirectory 2008 from a CSV

To create multiple users into ActiveDirectory 2008 Server from one single CSV file containing the users login information, you can use the following wsf file:

   1: <job id="main">
   2:  
   3:     <script language="VBScript">
   4:         dim text_out
   5:         text_out = ""
   6:         Dim oContainer 'Parent container of new   user 
   7:         Dim oUser 'Created user
   8:         'Get parentcontainer
   9:         Set oContainer=GetObject("LDAP://OU=yourouname, DC=your,DC=domain,DC=local")
  10:         'Read the file with user information
  11:         Const ForReading = 1
  12:         Set objFSO = CreateObject("Scripting.FileSystemObject")
  13:         Set objTextFile = objFSO.OpenTextFile _
  14:         ("users.txt", ForReading)
  15:         Do Until objTextFile.AtEndOfStream
  16:             strNextLine = objTextFile.Readline
  17:             user_info = Split(strNextLine , ",") 'split comma-delimited line
  18:             username = LCase(Left(user_info(0),1) & user_info(1))
  19:             'Create user
  20:             Set oUser = oContainer.Create("User","CN=" & user_info(0) & " " & user_info(1) )
  21:             'Assign properties values to user
  22:             oUser.Put "samAccountName",username
  23:             oUser.Put "givenName",user_info(0)
  24:             oUser.Put "sn",user_info(1)
  25:             oUser.Put "userPrincipalName",username & "@your.domain.local"
  26:             objUser.IsAccountLocked = False
  27:             oUser.SetPassword user_info(2)
  28:             oUser.SetInfo
  29:             'Clean up
  30:             Set oUser = Nothing
  31:             Set oContainer = Nothing
  32:         Loop
  33:         WScript.Echo "Finished"
  34:     </script>
  35: </job>

You CSV file (users.txt) must be located in the same folder where the script is and its contents must be in the following format (no headers):

  First Name, Last Name, Password

 

The script will use the first name and last name to create a username. It will take the first letter of the first name and the complete last name, for example: jsmith.

You will need to replace yourdomain in the script with the name of your Windows Domain. Also you need to change “yourouname” in the script to the name of the organizational unit that will hold your new users.

The code is under the MIT license.

Friday, August 14, 2009

How to do control breaks in Excel

One of the problems I find when exporting from RenWeb is that the names of the staff are repeated in every row when exporting to Excel. To make control breaks on the staff name (i.e. show the name only once) in excel you can use the following formula:

=IF(B1=B2,"",B2)

Change the B to the column that contains the names. The formula will set the cell blank if the contents of the current row in the B column is the same as the one in the previous row.

Tuesday, July 14, 2009

Windows.Forms’ DialogResult does not have OK as a member

I found this code to show up a “file browse” dialog from C#:

OpenFileDialog ofd = new OpenFileDialog();
DialogResult b = ofd.ShowDialog();
if (b == DialogResult.OK)
{
  CopySourceFiles.Text = ofd.FileName;
}

The problem was that it was giving an error saying that DialogResult did not have a member named OK. So I had to fully qualify DialogResult as the following snippet shows:

OpenFileDialog ofd = new OpenFileDialog();
System.Windows.Forms.DialogResult b = ofd.ShowDialog();
if (b == System.Windows.Forms.DialogResult.OK)
{
  CopySourceFiles.Text = ofd.FileName;
}

Friday, June 26, 2009

How to make Batch files run in Windows 2008 scheduled tasks

I was getting a 0x1 error every time Windows Server 2008 ran my task. I had programmed the task to run a bat file that would run a jruby script. The messages in the log did not help me at all, so I took a look at my script’s log. The log showed that the script was not being run at all. To fix this problem I had to make sure to enter the folder that contains the script in the start in field when configuring the scheduled task. So even it says it’s optional, make sure you enter a correct value in that field or else, the task will run with windows\system32 as the current working directory.

Thursday, June 11, 2009

Problems changing the SSL port number on Tomcat in Windows

I tried changing the SSL port number on my Tomcat server in my Windows Server 2008 machine and I kept getting the following error when going to the https version of my webapp:

Socket bind failed: [730048] Only one usage of each socket address (protocol/network address/port) is normally permitted.

To solve the problem I did the following:

  1. Re-installed apache using the Windows service installer and specifying the JDK’s JRE as the JRE to use.
  2. Set the keystoreFile attribute in the SSL connector tag in the server.xml file to a relative path. The path is based in Tomcat’s installation folder, so if you intalled it in c:\apache and specify ./mykey.bin in the  keystoreFile attribute, Tomcat will try to find the c:\apache\mykey.bin file.

Wednesday, June 10, 2009

How to split a full name in Excel

RenWeb exports the formal name in the form "Smith, John". Sometimes I need to split the formal name field into first name (including middle name) and last name. To get the formula to split the name I found this link from Pearson Software Consulting, LLC. Their formula to get the last name works great for me, but they were splitting the middle name from the first name, so for the first name I changed their formula to the following:

=TRIM(IF(ISERROR(FIND(",",A2,1)),A2,MID(A2,FIND(",",A2,1)+1,LEN(A2))))

 

To use the formula simply have the formal name in cell A2 and copy and paste the formula to another adjacent cell, such as B2. To get the first names of the rest of the people in the list simply use the auto fill values command from Excel.

How to split a full name in Excel

RenWeb exports the formal name in the form "Smith, John". Sometimes I need to split the formal name field into first name (including middle name) and last name. To get the formula to split the name I found this link from Pearson Software Consulting, LLC. Their formula to get the last name works great for me, but they were splitting the middle name from the first name, so for the first name I changed their formula to the following:

=TRIM(IF(ISERROR(FIND(",",A2,1)),A2,MID(A2,FIND(",",A2,1)+1,LEN(A2))))

 

To use the formula simply have the formal name in cell A2 and copy and paste the formula to another adjacent cell, such as B2. To get the first names of the rest of the people in the list simply use the auto fill values command from Excel.

Thursday, May 14, 2009

One more tool to convert MS Word text into clean HTML

Windows Live Writer is one of the best tools out there to convert MS Office Word formatted text into simple and clean HTML. To use it, just copy from a Word document and paste into Writer. Writer will covert the text to HTML without the obscure tags, FONTs and CSS styles that you would get if you were saving as HTML from Word. You can download it for free at http://download.live.com/writer.