Difference between revisions of "WPKG with Active Directory"
m (→Pulling workstation names to hosts.xml from Active Directory OUs automatically) |
|||
Line 69: | Line 69: | ||
# umount a share on AD (just in case), and then mount it | # umount a share on AD (just in case), and then mount it | ||
− | $server = "'''192.168. | + | $server = "'''192.168.55.66'''"; |
$share = "'''/mnt/$server'''"; | $share = "'''/mnt/$server'''"; | ||
Revision as of 12:32, 15 January 2007
Contents
Active Directory settings
Below settings for Active Directory - screenshots are in German, but I think anyone who doesn't know German, but saw Active Directory will know what to do:
Note that the above can be accomplished using the "Group Policy Management" tool.
Next, you have to choose the right settings for the execution of scripts:
Navigate to Computerkonfiguration -> Administrative Vorlagen -> System -> Skripts
e.g. Computer Configuration -> Administrative Templates -> System -> Scripts
Make sure that "Startscripts asynchron ausführen" is set to "Aktiviert"
e.g. Apply Startup scripts asynchronously is set to enabled
This make sure that the user can log in, even though the software is still being installed. It's a good choice, because some unpatient users will just press Reboot button when they can't log in immediately, which can have unexpected results (software not installed properly etc.).
Next thing to set is setting "Maximale Wartezeit für Gruppenrichtlinienskripts" (Maximum wait time for Group Policy scripts). Default is 600 seconds (10 minutes), which can be often not enough for installing some software, or when you install more than one software package. So a safe bet is 1800 seconds (30 minutes).
The last thing you have to do, is to select a script which will start WPKG on a system start. This script is located in a batch file:
\\server\path\to\WPKG\wpkg-start.bat
and contains the folowing line which starts WPKG:
cscript \\server\path\to\WPKG\wpkg.js /synchronize /quiet /nonotify
Notes
Sometimes a group policy is not applied when it is setup and the workstations are rebooted for the first time. The reason for this is that group policy is pulled from the server by default every ~90 minutes. If you require group policy to take effect immediately, you may run "gpupdate" (XP) or "secedit /refreshpolicy user_policy" and "secedit /refreshpolicy machine_policy" (Win2K) from each workstation.
Pulling workstation names to hosts.xml from Active Directory OUs automatically
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 perl script for that - you have to execute it on a Linux server, and you need to have ldapsearch
tool installed (it comes with OpenLDAP). It's not particularly beautiful, but it works.
Make sure you change the text in bold to match your settings:
#!/usr/bin/perl # All OUs that contain computer accounts @ous = ('ou=GR15-R1,ou=GR15,ou=classrooms,ou=uni', 'ou=FR7-FL,ou=FR7,ou=classrooms,ou=uni', 'ou=FR7-R3,ou=FR7,ou=classrooms,ou=uni', 'ou=FR5-R1,ou=FR5,ou=classrooms,ou=uni', 'ou=FR5-R1,ou=FR5,ou=classrooms,ou=uni', 'ou=Newinstallation,ou=uni', 'ou=Testinstallation,ou=uni', 'ou=temp,ou=uni'); # umount a share on AD (just in case), and then mount it $server = "192.168.55.66"; $share = "/mnt/$server"; system "umount $share"; system "mount.cifs //$server/Admin $share -o username=user,pass=password"; # Work on each OU foreach (@ous) { # Get "OU name" $_ =~ m/ou=([a-zA-Z0-9-]*)/; $OU = "$1"; # LDAP command to retrieve data from a given OU $ldapcommand = "ldapsearch -h $server -b \"$_,dc=example,dc=com\" -x -s sub \"objectclass=computer\"" . " -w password -D \"cn=LDAP user,ou=IT,ou=uni,dc=example,dc=com\""; # execute LDAP command open( LDAPQUERY, "$ldapcommand |" ) or die "LDAP query error: $!"; # Get all fields that have cn=... while ( <LDAPQUERY> ) { next if ! /^cn: (.*)$/; $cn = $1; # ...and append them to @results push @results, "$cn"; } # Create $hosts variable with some content... $hosts = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<wpkg>\n"; # ...and append hosts that we found (cn=) to that variable... foreach (@results) { $computer = $_; # ...with proper syntax / formatting $hosts = $hosts."<host name=\"$computer\" profile-id=\"$OU\" />\n"; } # Append an ending to the file $hosts = $hosts."</wpkg>\n"; # Where to put the xml file - in this case, we don't overwrite what's in WPKG/hosts $data_file = "$share/WPKG/hosts/created_from_AD/$OU.xml"; # Open the file for writing open DATA, ">$data_file" or die "can't open $data_file $!"; # Append data to the file print DATA "$hosts"; # Clear @results undef @results; } # close the file and umount a share on EDU DC close DATA; system "umount $share";
Cron entry
You can start it every hour via cron on your Linux system:
# generate hosts.xml from AD 01 * * * * root perl /opt/ldap-wpkg.pl &>/dev/null