Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
# Gets a list of users from the PDC and prints them to accounts.txt # This is used in conjunction with 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

In reply to Find orphaned home directories by OzzyOsbourne

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2017-02-28 00:05 GMT
    Find Nodes?
      Voting Booth?
      Before electricity was invented, what was the Electric Eel called?

      Results (393 votes). Check out past polls.