use strict; use Win32::NetAdmin qw(GetUsers UserGetAttributes); my (@accounts,%is_acct,$x,$key,$homeDir,$account); my $PDC='thePDC'; my $filter='FILTER_NORMAL_ACCOUNT'; my $out='//ws/share/orphan.txt'; my ($server,$usershare); my @servers=('server1','server2'); # Slurp all accounts into @accounts... GetUsers($PDC,$filter, \@accounts) or die "Can't get users $!"; undef %is_acct; # Create a hash with user accounts and home directory paths foreach $account(@accounts){ UserGetAttributes($PDC,$account,$x,$x,$x,$homeDir,$x,$x,$x) or die "UserGetAttributes() failed: $^E"; $is_acct{$account}=$homeDir; } open OUT,">$out"; # Check for user shares on D$ and E$ and exit if not there... foreach $server (@servers){ my $dir1="//$server/e\$/usershare"; if (!(-e "$dir1")){#if directory doesn't exist try d$ $dir1="//$server/d\$/usershare"; 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; foreach $usershare(@dirs){ my $userdir="$dir1/$usershare"; # PLACE WHERE PARTIAL EXTRACTION GOES... # used to read if(!exists $is_acct{$usershare}){ # print "$userdir: Orphan\n"; # } } } close OUT;