Changes

Jump to: navigation, search

WPKG with Active Directory

1,745 bytes added, 12:37, 2 June 2010
no edit summary
# generate hosts.xml from AD
01 * * * * root perl /opt/ldap-wpkg.pl &>/dev/null
 
= Pulling workstation names to hosts.xml from Active Directory OUs automatically with python =
 
if you have different OUs in your AD, and these OUs use different software settings, you will likely want to generate hosts.xml from your AD tree. Here is a simple python script for that - you have to execute it on a Linux server, and you need to have python-ldap installed.
 
<source lang="python">
 
#!/usr/bin/python
import ldap, string, os, time, sys
hostfilepath = "/path/WPKG/hosts/created_from_AD/hosts.xml"
domain = "example.com"
l=ldap.initialize("ldap://dc1."+domain+":389")
l.simple_bind_s("domain\\username","password")
scope = 'dc=example,dc=com'
os.system('/bin/rm -rf %s' % ("/path/WPKG/hosts/created_from_AD/hosts.xml"))
 
HostFile = open("/path/WPKG/hosts/created_from_AD/hosts.xml","a+")
HostFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<wpkg>\n")
try:
res = l.search_s(scope, ldap.SCOPE_SUBTREE, "(&(ObjectCategory=computer) )", ['name', 'canonicalName'])
 
for (dn, vals) in res:
accountname = vals['name'][0].lower()
try:
ou = vals['canonicalName'][0].lower()
except:
ou = vals['name'][0].lower()
 
ou = ou.replace(accountname,' ')
ou = ou.replace(' ','')
ou = ou.replace('/','-')
ou = ou.rstrip('-')
 
 
HostFile.writelines("<host name=" + '"' + accountname + '"' + " profile-id=" + '"' + ou + '"' + " />\n")
except ldap.LDAPError, error_message:
print error_message
 
HostFile.writelines("</wpkg>\n")
HostFile.close()
l.unbind_s()
</source>
= Pulling workstation names to hosts.xml from Active Directory OUs automatically with vbScript=
Wscript.Echo "Finished..."
</source>
== Cron entry ==
 
You can start it every hour via cron on your Linux system:
 
# generate hosts.xml from AD
01 * * * * root python /opt/ldap-wpkg.py &>/dev/null
== Multiple Profile Method ==
Anonymous user

Navigation menu