# Compares directories on the servers against who is using them in user manager # If no one claims the directory in user manager, it is dubbed an orphan 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 (){ 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;