I was reading up on iPhone in the enterprise and saw something about Mobile Device Management servers. As far as I can tell, there are a few 3rd party MDM vendors, but Apple
You better follow the apple provided ruby code. Set it up and make it working. After that you can simply convert that to any language. That worked for me.