# Gets a list of users from the PDC and prints them to accounts.txt
# This is used in conjunction with orphan.pl to find orphaned home dir
+ectories.
use strict;
use Win32::NetAdmin qw(GetUsers UserGetAttributes);
my (@accounts,$x,$homeDir,$account);
my $PDC='yourPDC';
my $filter='FILTER_NORMAL_ACCOUNT';
my $out='accounts.txt';
# Slurp all accounts into @accounts...
GetUsers($PDC,$filter, \@accounts) or die "Can't get users $!";
print "got accounts\n";
open OUT,">$out";
foreach $account(@accounts){
UserGetAttributes($PDC,$account,$x,$x,$x,$homeDir,$x,$x,$x) or war
+n "UserGetAttributes() failed: $^E";
$homeDir=lc ($homeDir);
print OUT "$account\t$homeDir\n";
}
close OUT;
End of script 1
Start of script 2
# Compares directories on the servers against who is using them in use
+r manager
# If no one claims the directory in user manager, it is dubbed an orph
+an and
# printed to orphans.txt
use strict;
use Win32::NetAdmin qw(GetUsers UserGetAttributes);
my (@accounts,%is_acct,$x,$key,$homeDir,$account,$userDir,$server);
my $PDC='yourPDC';
my @servers=('yourserver1','yourserver2');
my $filter='FILTER_NORMAL_ACCOUNT';
my $in='accounts.txt';
my $out='orphans.txt';
# Slurp all accounts into @accounts...
print "Got accounts\n";
%is_acct=();
open (IN,"<$in");
open (OUT,">$out");
# Create a hash with user accounts and home directory paths
while (<IN>){
chomp;
s/\\/\//g;
($account, $homeDir) = split /\t/;
$homeDir = lc ($homeDir);
$is_acct{$homeDir}=$account;
}
print "Hash complete\n";
# Check for user shares on D$ and E$ and exit if not there...
foreach $server (@servers){
my $dir1="//$server/d\$/users";
if (!(-e "$dir1")){#if directory doesn't exist try d$
$dir1="//$server/e\$/users";
if (!(-e "$dir1")){#if directory doesn't exist try d$
$dir1="//$server/users";
if (!(-e "$dir1")){
next;
}
}
}
# Read in the user shares from the servers
opendir(DIR, $dir1) or die "can't opendir $dir1: $!";
my @dirs = grep { !/^\./ && -d "$dir1/$_" } readdir(DIR) or warn "
+can't grep"; #weed out dots and get only dirs
closedir DIR;
@dirs = map (lc "//$server/$_", @dirs);
print "read directories from $server\n";
foreach $userDir (@dirs){
print OUT "$userDir";
if(!exists $is_acct{$userDir}){
print OUT ": Orphan";
}
print OUT "\n";
}
}
close OUT;
End of script 2
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.