Changes
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 ==