In the past there have been several published hints on the /usr/sbin/networksetup command. However, until recently (well since 10.6.x) that command was not able to add passkeys to the keychain. I just received 500 new MacBooks to image in my enterprise and these brand new ones will only run 10.6. The rest of our deployment is still on 10.5.8 because we never had the desire to re-image 40 OS X Servers and 8,000 clients with 10.6.
So, I just modified my post image shell script to have a line that does a simple case statement and if it outputs 10.6* it executes this line of code:
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex Airport my_ssid 0 my_security my_passkey
Mac OS X Hints
http://hints.macworld.com/article.php?story=20101004114849586