--- old Wed Jan 21 20:25:54 2004 +++ new Wed Jan 21 20:26:45 2004 @@ -1,3 +1,5 @@ +#!/usr/bin/perl + use Getopt::Long; use Win32; use Win32::OLE qw( in ); @@ -13,125 +15,54 @@ my( $fMachine, $Name ) = ( $Domain =~ /(\\\\)?(.*)$/ ); my $Class = ( "" eq $fMachine )? "domain" : "computer"; - print "WinNT://$Name,$Class"; if ( my $AD = Win32::OLE->GetObject( "WinNT://$Name,$Class" ) ) { # user accounts only $AD->{Filter} = [ "User" ]; - print "Crap\n"; foreach my $User ( in($AD) ) { - if( $User->{AccountDisabled} == $Config{disable} ) { if ($User->{Name} =~ /^[a-zA-Z]{8}?$/) { - $dn = SearchAD( "$User->{Name}" );#cw0831 adamwolf + my $PropertyList = GetProperties( $User ); - sub SearchAD - { - ($Account) = @_; - undef $AdsPath; - $Root = Win32::OLE->GetObject("LDAP://RootDSE"); - $DefaultDomainNC = $Root->Get("DefaultNamingContext"); - undef $Root; - if ("" eq $DefaultDomainNC) - { - Win32::MsgBox("Error. Did not get the Default Naming Context", - MB_ICONSTOP , "Source User Error"); - return; - } - $ADOConn = Win32::OLE->new("ADODB.Connection"); - $ADOConn->{Provider} = ("ADsDSOObject"); - $ADOConn->{ConnectionString} = ($DefaultDomainNC); - $ADOConn->Open("Active Directory Provider"); - - $ADOCommand = Win32::OLE->new("ADODB.Command"); - $ADOCommand->{ActiveConnection} = $ADOConn; - - $ADSQuery = "SELECT AdsPath FROM \'LDAP://$DefaultDomainNC\' WHERE samAccountName = \'$Account\' "; - $ADOCommand->{CommandText} = $ADSQuery; - $ResultSet = Win32::OLE->new("ADODB.Recordset"); - $ResultSet = $ADOConn->Execute($ADSQuery); - $AdsPath = $ResultSet->Fields(0)->{Value}; - $ResultSet->Close; - $ADOConn->Close; - return($AdsPath); - } - - $ADSIObj = Win32::OLE ->GetObject( "$dn" ); - #$ADSIObj->MoveHere("$dn", "cn=jdoe"); - #Set usr = ou.CreateObject ("user", "cn=jsmith") - #usr.Put "samAccountName", "jsmith" - #usr.Put "userPrincipalName", jsmith@wrox.com - #usr.setInfo - my $PropertyList = GetProperties( $ADSIObj ); - - # ASP example of add user to AD - #Set ou = GetObject(".") - #Set usr = ou.CreateObject ("user", "cn=jsmith") - #usr.Put "samAccountName", "jsmith" - #usr.Put "userPrincipalName", jsmith@wrox.com - #usr.setInfo - - # ASP example of rename an object in the Active di - #ou = GetObject(".cn=johnd") - #ou.MoveHere (usr.ADsPath, "cn=jdoe") - -# print "\ndisplayName = $ADSIObj->{displayName}\n"; -# my $userPrincipalName = $ADSIObj->{Name}; -# @user_name = split /=/, $userPrincipalName; - #$userPrincipalName .= "\@lbcrsed.net"; - #print "userPrincipalName = $userPrincipalName\n"; -# $ADSIObj->{userPrincipalName} = "$user_name[1]"; - -# $givenName = $ADSIObj->{displayName}; -# $givenName =~ s/^(\w+)(.*)/$1/; - #print "givenName = $givenName\n"; -# $ADSIObj->{givenName} = "$givenName"; - - #$ADSIObj->{cn} = $ADSIObj->{displayName}; - -# $sn = $ADSIObj->{displayName}; -# $sn =~ s/^(.*)(\s)(\w+)/$3/; - #print "sn = $sn\n"; -# $ADSIObj->{sn} = "$sn"; - - #print "CN=$ADSIObj->{displayName}\n"; - #$ADSIObj->{name} = "CN=$ADSIObj->{displayName}"; - #$ADSIObj->{cn} = "$ADSIObj->{displayName}"; - #die; - - $ADSIObj->{profilePath} = ""; - $ADSIObj->SetInfo; # Don't forget to set the values - -# print "\n\n$ADSIObj->{Name}\n\n"; -# my $PropertyList = GetProperties( $ADSIObj ); -# foreach ( sort( @{$PropertyList} ) ) -# { -# next if( " " eq $_ ); -# print "\t $_: $ADSIObj->{$_}\n"; -# } - die; - sub GetProperties - { - my( $Obj ) = @_; - my @Properties; - - if ( my $Schema = Win32::OLE->GetObject( $Obj->{Schema} ) ) - { - foreach ( $Schema->{MandatoryProperties}, - $Schema->{OptionalProperties} ) - { - push( @Properties, @{$_} ) if( defined $_ ); - } - } - return ( \@Properties ); - } + print " $Domain\\$User->{Name}\n"; + print " $User->{Profile}\n"; + $User->{Profile} = ""; + $User->SetInfo; # Don't forget to set the values + + #print "\n\n$ADSIObj->{Name}\n\n"; + #foreach ( sort( @{$PropertyList} ) ) + #{ + # next if( " " eq $_ ); + # print "\t $_: $User->{$_}\n"; + #} + print " $User->{Profile}\n\n"; + #$User->{profilePath} = "value"; + #$ADSIObj->SetInfo; # Don't forget to set the valu ++es } + } } } +} + +sub GetProperties +{ + my( $Obj ) = @_; + my @Properties; + + if ( my $Schema = Win32::OLE->GetObject( $Obj->{Schema} ) ) + { + foreach ( $Schema->{MandatoryProperties}, + $Schema->{OptionalProperties} ) + { + push( @Properties, @{$_} ) if( defined $_ ); + } + } + return ( \@Properties ); } sub Configure