Zentyal Bulk LDAP passwords change

This is a small script I have done today in Zentyal that allows you to change the passwords of all users in LDAP. It creates a file /tmp/usuarios.csv with the users and their new passwords

#!/usr/bin/perl
use strict;
use warnings;
use EBox;
use EBox::UsersAndGroups;
use EBox::Global;
use EBox::Util::Random;
EBox::init();

my $salida ="/tmp/users.csv";
open (OUT,">$out") || die "ERROR: Can't create or write to file $out\n";
my $users = EBox::Global->modInstance('users');
my @userlist = @{$users->users()   }  ;
foreach my $user (@userlist) {
        my $password;
        $password =  EBox::Util::Random::generate(8);
        print OUT $user->name()." ". $password."\n";
        $user->changePassword($password,0)
}
  close (OUT);

 

Deja un comentario