foreach my $Machine ( @MachineList ) { ( $Machine = "\\\\$Machine" ) =~ s/^\\+/\\\\/; print "Querying $Machine\n"; foreach my $Account ( sort keys %AccountList ) { my %Attrib; if( Win32::AdminMisc::UserGetMiscAttributes( $Machine, $Account, \%Attrib ) ) { my $Data = $Result{$Machine}{$Account} = {}; $Data->{fullname} = $Attrib{USER_FULL_NAME}; if( $Data->{lastlogon}->{value} < $Attrib{USER_LAST_LOGON} ) { $Data->{lastlogon}->{value} = $Attrib{USER_LAST_LOGON}; $Data->{lastlogon}->{machine} = $Machine; } if( $Data->{lastlogoff}->{value} < $Attrib{USER_LAST_LOGOFF} ) { $Data->{lastlogoff}->{value} = $Attrib{USER_LAST_LOGOFF}; $Data->{lastlogoff}->{machine} = $Machine; } $Data->{badpwcount} += $Attrib{USER_BAD_PW_COUNT}; $Data->{logons} += $Attrib{USER_NUM_LOGONS}; } } } foreach my $Machine ( sort keys %Result ) { my $MachineInfo = $Results{$Machine}; foreach my $Account ( sort keys %{$MachineInfo} ) { print "$Account ($MachineInfo->{$Account}{fullname}):\n"; print Report( "Last logon", $MachineInfo->{$Account}{lastlogon} ), "\n"; print Report( "Last logoff", $MachineInfo->{$Account}{lastlogoff} ), "\n"; print "\tTotal number of bad password attempts: "; print "$MachineInfo->{$Account}{badpwcount}\n"; print "\tTotal number of logons: $MachineInfo->{$Account}{logons}\n"; print "\n"; } } sub Report { my( $Field, $Data ) = @_; my $Date = scalar localtime($Data->{value} ); my $Location = "( $Data->{machine} )"; $Date = "Not available" if( 0 == $Data->{value} ); $Location = "" if( 0 == $Data->{value} ); return( "\t$Field: $Date $Location" ); }