Question about getting user information from Active Directory

Hello all,

I am new to Ruby. I need a script to get a user's information from
Microsoft Active Directory.

Below is my script.

                require 'rubygems'
                require 'active_directory'
                
                settings = {
                    :host => '192.168.56.102',
                    :base => 'dc=test,dc=com',
                    :port => 636,
                    :encryption => :simple_tls,
                    :auth => {
                        :method => :simple,
                        :username => "username",
                        :password => "password"
                    }
                }
                ActiveDirectory::Base.setup(settings)
                user=ActiveDirectory::User.find(:first, :sAMAccountName => 'logonname')
                puts user.inspect
                
And below is the output. It looks like what I need are in @myhash, but
how to get this hash or I have to parse it as string?

#<ActiveDirectory::User:0x00000001614ee0
@entry=#<Net::LDAP::Entry:0x0000000161ad90 @myhash={:dn=>["CN=firstname
middle. lastname,DC=test,DC=com"], :objectclass=>["top",
"person", "organizationalPerson", "user"], :cn=>["firstname middle.
lastname"], :sn=>["lastname"], :givenname=>["firstname"],
:initials=>["middle"], :distinguishedname=>["CN=firstname middle.
lastname,DC=test,DC=com"], :instancetype=>["4"],
:whencreated=>["20150326061809.0Z"],
:whenchanged=>["20150326101808.0Z"], :displayname=>["firstname middle.
lastname"], :usncreated=>["24686"],
:memberof=>["CN=group1,DC=test,DC=com"],
:usnchanged=>["24732"], :name=>["firstname middle. lastname"],
:objectguid=>["\x1DE,\x0E\x18u\x0FF\xABI\xFA\x15u\x88>w"],
:useraccountcontrol=>["512"], :badpwdcount=>["0"], :codepage=>["0"],
:countrycode=>["0"], :badpasswordtime=>["0"], :lastlogoff=>["0"],
:lastlogon=>["0"], :pwdlastset=>["0"], :primarygroupid=>["513"],
:objectsid=>["\x01\x05\x00\x00\x00\x00\x00\x05\x15\x00\x00\x00\x04\xA6R\xE9\xAA-\xAAH5\xF6~aR\x04\x00\x00"],
:accountexpires=>["9223372036854775807"], :logoncount=>["0"],
:samaccountname=>["logonname"], :samaccounttype=>["805306368"],
:userprincipalname=>["logonname@test.com"], :lockouttime=>["0"],
:objectcategory=>["CN=Person,CN=Schema,CN=Configuration,DC=test,DC=com"],
:dscorepropagationdata=>["20150326094402.0Z", "20150326094349.0Z",
"16010101000416.0Z"], :mail=>["test@test.com"]}>, @attributes={}>

Thanks.

···

--
Rex Zhang <rexzhang@cienet.com.cn>

Hello Rex,

And below is the output. It looks like what I need are in @myhash, but
how to get this hash or I have to parse it as string?

According to the documentation [1], you can either use the #get_attr instance
method or rely on #method_missing to turn any key into a proper call to
#get_attr.

E.g.:

  user.get_attr :name
  user.name

HTH.

    --- Eric

[1] Class: ActiveDirectory::Base — Documentation for active_directory (1.6.0)

···

On Thursday 26 March 2015 19:33:24, Rex Zhang <rexzhang@cienet.com.cn> wrote:

Thank your Eric.

I tried this before. But it seems that not all attributes can be queried
such as whencreated and whenchanged.

        require 'rubygems'
        require 'active_directory'
        
        # Uses the same settings as net/ldap
        
        settings = {
            :host => '192.168.56.102',
            :base => 'dc=test,dc=com',
            :port => 636,
            :encryption => :simple_tls,
            :auth => {
                :method => :simple,
                :username => "username",
                :password => "password"
            }
        }
        ActiveDirectory::Base.setup(settings)
        
        user=ActiveDirectory::User.find(:first, :sAMAccountName => 'logonname')
        
        arg=['cn', 'samaccountName', 'memberof', 'disabled?', 'password_never_expires?', 'locked?', 'expired?', 'mail', 'displayName', 'distinguishedName', 'givenName', 'initials', 'sn', 'badPwdCount', 'whencreated', 'whenchanged', 'lastLogon']
        userinfo={}
        
        arg.each do |argx|
          begin
            userinfo[argx] = user.send(argx).to_s
          rescue
            userinfo[argx] = 'nil'
          end
        end
        puts "User Information:"
        userinfo.each_key do |key|
          puts "#{key} => "+userinfo[key]
        end

And below is the output. You can see that some attributes always be nil.

User Information:

        cn => firstname middle. lastname
        samaccountName => logonname
        memberof => [#<ActiveDirectory::Group:0x000000021566f0 @entry=#<Net::LDAP::Entry:0x00000002166500 @myhash={:dn=>["CN=group1,OU=OU-IT,DC=test,DC=com"], :objectclass=>["top", "group"], :cn=>["group1"], :member=>["CN=firstname middle. lastname,OU=OU-IT,DC=test,DC=com"], :distinguishedname=>["CN=group1,OU=OU-IT,DC=test,DC=com"], :instancetype=>["4"], :whencreated=>["20150326101906.0Z"], :whenchanged=>["20150326101926.0Z"], :usncreated=>["24735"], :usnchanged=>["24739"], :name=>["group1"], :objectguid=>["\xF3\x88\x00\xE7\xBA\xCE\x1FF\x92\x9F]\xCB\xDD\xE0\xD8l"], :objectsid=>["\x01\x05\x00\x00\x00\x00\x00\x05\x15\x00\x00\x00\x04\xA6R\xE9\xAA-\xAAH5\xF6~aS\x04\x00\x00"], :samaccountname=>["group1"], :samaccounttype=>["268435456"], :grouptype=>["-2147483646"], :objectcategory=>["CN=Group,C
N=Schema,CN=Configuration,DC=test,DC=com"], :dscorepropagationdata=>["16010101000000.0Z"]}>, @attributes={}>]
        disabled? => false
        password_never_expires? => false
        locked? => false
        expired? => false
        mail => test@test.com
        displayName => firstname middle. lastname
        distinguishedName => CN=firstname middle. lastname,OU=OU-IT,DC=test,DC=com
        givenName => firstname
        initials => middle
        sn => lastname
        badPwdCount => 0
        whencreated => nil
        whenchanged => nil
        lastLogon => 0

Do you have any idea how to get whencreated and whenchanged attributes?
Thanks.

Rex

···

On Thu, 2015-03-26 at 23:23 +0100, Eric MSP Veith wrote:

Hello Rex,

On Thursday 26 March 2015 19:33:24, Rex Zhang <rexzhang@cienet.com.cn> wrote:
> And below is the output. It looks like what I need are in @myhash, but
> how to get this hash or I have to parse it as string?

According to the documentation [1], you can either use the #get_attr instance
method or rely on #method_missing to turn any key into a proper call to
#get_attr.

E.g.:

  user.get_attr :name
  user.name

HTH.

    --- Eric

[1] Class: ActiveDirectory::Base — Documentation for active_directory (1.6.0)

--
Rex Zhang <rexzhang@cienet.com.cn>

What happens when you just do

  p user.get_attr :whencreated

?

The missing piece of information is obviously there in the User object.

Btw, why the dance with Object#send? There's #get_attr for your User object;
you could easily work with that, e.g.

  %i(cn displayName whencreated whenchanged).each do |i|
    puts "#{i} => #{user.get_attr i}"
  end

HTH.
      --- Eric

···

On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:

Thank your Eric.

I tried this before. But it seems that not all attributes can be queried
such as whencreated and whenchanged.

Hello Eric,

Thank you Eric. Your example is better and clear.

Below is error output when just do:

        p user.get_attr :whencreated

        /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in `decode': undefined method `parse' for Time:Class (NoMethodError)
        
        from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in `decode_field'
        
        from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in `get_attr'
        
        from /home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in `<top (required)>'
          from -e:1:in `load'
          from -e:1:in `<main>'

Regards,
Rex

···

On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith wrote:

On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:
> Thank your Eric.
>
> I tried this before. But it seems that not all attributes can be queried
> such as whencreated and whenchanged.

What happens when you just do

  p user.get_attr :whencreated

?

The missing piece of information is obviously there in the User object.

Btw, why the dance with Object#send? There's #get_attr for your User object;
you could easily work with that, e.g.

  %i(cn displayName whencreated whenchanged).each do |i|
    puts "#{i} => #{user.get_attr i}"
  end

HTH.
      --- Eric

--
Rex Zhang <rexzhang@cienet.com.cn>

Hi Rex.

I guess this is a Ruby-related issue. What version of Ruby do you use?

Have a good day.

···

2015-03-30 6:46 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:

Hello Eric,

Thank you Eric. Your example is better and clear.

Below is error output when just do:

p user.get_attr :whencreated

/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in
`decode': undefined method `parse' for Time:Class (NoMethodError)
from
/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in
`decode_field'
from
/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in
`get_attr'
from
/home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in
`<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

Regards,
Rex

On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith wrote:

On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:> Thank your Eric.> > I tried this before. But it seems that not all attributes can be queried> such as whencreated and whenchanged.

What happens when you just do

  p user.get_attr :whencreated

?

The missing piece of information is obviously there in the User object.

Btw, why the dance with Object#send? There's #get_attr for your User object;
you could easily work with that, e.g.

  %i(cn displayName whencreated whenchanged).each do |i|
    puts "#{i} => #{user.get_attr i}"
  end

HTH.
      --- Eric

  --
Rex Zhang <rexzhang@cienet.com.cn>

--
İyi günler.
İsmail Arılık

Hi Ismail,

Ruby version: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Regards,
Rex

···

On Mon, 2015-03-30 at 09:21 +0300, İsmail Arılık wrote:

Hi Rex.

I guess this is a Ruby-related issue. What version of Ruby do you use?

Have a good day.

2015-03-30 6:46 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:

        Hello Eric,
        
        Thank you Eric. Your example is better and clear.
        
        Below is error output when just do:
        
                p user.get_attr :whencreated
        
                /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in `decode': undefined method `parse' for Time:Class (NoMethodError)
                from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in `decode_field'
                from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in `get_attr'
                from /home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in `<top (required)>'
                from -e:1:in `load'
                from -e:1:in `<main>'
        
        Regards,
        Rex
        
        On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith wrote:
        
        > On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:
        > > Thank your Eric.
        > >
        > > I tried this before. But it seems that not all attributes can be queried
        > > such as whencreated and whenchanged.
        >
        > What happens when you just do
        >
        > p user.get_attr :whencreated
        >
        > ?
        >
        > The missing piece of information is obviously there in the User object.
        >
        > Btw, why the dance with Object#send? There's #get_attr for your User object;
        > you could easily work with that, e.g.
        >
        > %i(cn displayName whencreated whenchanged).each do |i|
        > puts "#{i} => #{user.get_attr i}"
        > end
        >
        > HTH.
        > --- Eric
        
--
Rex Zhang <rexzhang@cienet.com.cn>

I have researched and saw required `Time` class was not required in the
related `date.rb` file. It seems like a bug. The link of the file is below
and maybe you want to research deeply and open an issue in the Github page:

···

2015-03-30 9:32 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:

Hi Ismail,

Ruby version: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Regards,
Rex

On Mon, 2015-03-30 at 09:21 +0300, İsmail Arılık wrote:

Hi Rex.

I guess this is a Ruby-related issue. What version of Ruby do you use?

Have a good day.

2015-03-30 6:46 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:

Hello Eric,

Thank you Eric. Your example is better and clear.

Below is error output when just do:

p user.get_attr :whencreated

/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in
`decode': undefined method `parse' for Time:Class (NoMethodError)
from
/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in
`decode_field'
from
/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in
`get_attr'
from
/home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in
`<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

Regards,
Rex

On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith wrote:

On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:> Thank your Eric.> > I tried this before. But it seems that not all attributes can be queried> such as whencreated and whenchanged.

What happens when you just do

  p user.get_attr :whencreated

?

The missing piece of information is obviously there in the User object.

Btw, why the dance with Object#send? There's #get_attr for your User object;
you could easily work with that, e.g.

  %i(cn displayName whencreated whenchanged).each do |i|
    puts "#{i} => #{user.get_attr i}"
  end

HTH.
      --- Eric

    --
Rex Zhang <rexzhang@cienet.com.cn>

--
İyi günler.
İsmail Arılık

Thank you very much! After change "Time.parse(remote_time)" to
"remote_time", the problem seems resolved.

      # Decodes an Active Directory date when stored as ISO8601

···

#
      def self.decode(remote_time)
        Time.parse(remote_time) # Change this line to remote_time
      end

Regards,
Rex

On Mon, 2015-03-30 at 09:40 +0300, İsmail Arılık wrote:

I have researched and saw required `Time` class was not required in
the related `date.rb` file. It seems like a bug. The link of the file
is below and maybe you want to research deeply and open an issue in
the Github page:

active_directory/lib/active_directory/field_type/date.rb at master · ajrkerr/active_directory · GitHub

2015-03-30 9:32 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:

        Hi Ismail,
        
        Ruby version: ruby 2.1.5p273 (2014-11-13 revision 48405)
        [x86_64-linux]
        
        Regards,
        Rex
        
        On Mon, 2015-03-30 at 09:21 +0300, İsmail Arılık wrote:
        
        > Hi Rex.
        >
        >
        > I guess this is a Ruby-related issue. What version of Ruby
        > do you use?
        >
        >
        > Have a good day.
        >
        > 2015-03-30 6:46 GMT+03:00 Rex Zhang
        > <rexzhang@cienet.com.cn>:
        >
        > Hello Eric,
        >
        > Thank you Eric. Your example is better and clear.
        >
        > Below is error output when just do:
        >
        >
        > p user.get_attr :whencreated
        >
        >
        >
        > /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in `decode': undefined method `parse' for Time:Class (NoMethodError)
        > from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in `decode_field'
        > from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in `get_attr'
        > from /home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in `<top (required)>'
        > from -e:1:in `load'
        > from -e:1:in `<main>'
        >
        >
        > Regards,
        > Rex
        >
        >
        >
        >
        > On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith > > wrote:
        >
        > > On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:
        > > > Thank your Eric.
        > > >
        > > > I tried this before. But it seems that not all attributes can be queried
        > > > such as whencreated and whenchanged.
        > >
        > > What happens when you just do
        > >
        > > p user.get_attr :whencreated
        > >
        > > ?
        > >
        > > The missing piece of information is obviously there in the User object.
        > >
        > > Btw, why the dance with Object#send? There's #get_attr for your User object;
        > > you could easily work with that, e.g.
        > >
        > > %i(cn displayName whencreated whenchanged).each do |i|
        > > puts "#{i} => #{user.get_attr i}"
        > > end
        > >
        > > HTH.
        > > --- Eric
        >
        >
        >
        >
        >
        >
        
--
Rex Zhang <rexzhang@cienet.com.cn>

Like Ismail pointed it. Seems like the Time class isn't required. You removed the Time.parse method call and the error went away. Revert that change since that really isn't a fix it's a side effect. What happens if you add...

require 'time'

at the top above module?

Jorge Colon

Senior Software Architect/Owner
2UP Media
c: 407.489.2677
info@2upmedia.com
www.2upmedia.com

LinkedIn
PHP Zend Certified Engineer

···

On Mar 30, 2015, at 2:55 AM, Rex Zhang <rexzhang@cienet.com.cn> wrote:

Thank you very much! After change "Time.parse(remote_time)" to "remote_time", the problem seems resolved.
active_directory/lib/active_directory/field_type/date.rb at master · ajrkerr/active_directory · GitHub

# Decodes an Active Directory date when stored as ISO8601
      #
      def self.decode(remote_time)
        Time.parse(remote_time) # Change this line to remote_time
      end

Regards,
Rex

On Mon, 2015-03-30 at 09:40 +0300, İsmail Arılık wrote:
I have researched and saw required `Time` class was not required in the related `date.rb` file. It seems like a bug. The link of the file is below and maybe you want to research deeply and open an issue in the Github page:
active_directory/lib/active_directory/field_type/date.rb at master · ajrkerr/active_directory · GitHub
2015-03-30 9:32 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:
Hi Ismail,

Ruby version: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Regards,
Rex

On Mon, 2015-03-30 at 09:21 +0300, İsmail Arılık wrote:
Hi Rex.

I guess this is a Ruby-related issue. What version of Ruby do you use?

Have a good day.

2015-03-30 6:46 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:
Hello Eric,

Thank you Eric. Your example is better and clear.

Below is error output when just do:

p user.get_attr :whencreated

/home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in `decode': undefined method `parse' for Time:Class (NoMethodError)
from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in `decode_field'
from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in `get_attr'
from /home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

Regards,
Rex

On Fri, 2015-03-27 at 15:26 +0100, Eric MSP Veith wrote:
On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:
> Thank your Eric.
>
> I tried this before. But it seems that not all attributes can be queried
> such as whencreated and whenchanged.

What happens when you just do

  p user.get_attr :whencreated

?

The missing piece of information is obviously there in the User object.

Btw, why the dance with Object#send? There's #get_attr for your User object;
you could easily work with that, e.g.

  %i(cn displayName whencreated whenchanged).each do |i|
    puts "#{i} => #{user.get_attr i}"
  end

HTH.
      --- Eric

--
Rex Zhang <rexzhang@cienet.com.cn>

Hi Jorge,

Thank you for your suggestion.

After remove Time.parse method, the output is like below:
whencreated => 20150319102224.0Z

After add require 'time', it makes better readability.
whencreated => 2015-03-19 10:22:24 UTC

Regards,
Rex

···

On Mon, 2015-03-30 at 03:19 -0400, Jorge Colon wrote:

Like Ismail pointed it. Seems like the Time class isn't required. You
removed the Time.parse method call and the error went away. Revert
that change since that really isn't a fix it's a side effect. What
happens if you add...

require 'time'

at the top above module?

Jorge Colon

Senior Software Architect/Owner
2UP Media
c: 407.489.2677
info@2upmedia.com
www.2upmedia.com

LinkedIn
PHP Zend Certified Engineer

On Mar 30, 2015, at 2:55 AM, Rex Zhang <rexzhang@cienet.com.cn> wrote:

> Thank you very much! After change "Time.parse(remote_time)" to
> "remote_time", the problem seems resolved.
> active_directory/lib/active_directory/field_type/date.rb at master · ajrkerr/active_directory · GitHub
>
> # Decodes an Active Directory date when stored as ISO8601
>
> #
> def self.decode(remote_time)
> Time.parse(remote_time) # Change this line to remote_time
> end
>
>
>
> Regards,
> Rex
>
> On Mon, 2015-03-30 at 09:40 +0300, İsmail Arılık wrote:
>
> > I have researched and saw required `Time` class was not required
> > in the related `date.rb` file. It seems like a bug. The link of
> > the file is below and maybe you want to research deeply and open
> > an issue in the Github page:
> >
> >
> > active_directory/lib/active_directory/field_type/date.rb at master · ajrkerr/active_directory · GitHub
> >
> >
> > 2015-03-30 9:32 GMT+03:00 Rex Zhang <rexzhang@cienet.com.cn>:
> >
> > Hi Ismail,
> >
> > Ruby version: ruby 2.1.5p273 (2014-11-13 revision 48405)
> > [x86_64-linux]
> >
> >
> > Regards,
> > Rex
> >
> >
> >
> >
> >
> >
> > On Mon, 2015-03-30 at 09:21 +0300, İsmail Arılık wrote:
> >
> > > Hi Rex.
> > >
> > >
> > > I guess this is a Ruby-related issue. What version of
> > > Ruby do you use?
> > >
> > >
> > > Have a good day.
> > >
> > > 2015-03-30 6:46 GMT+03:00 Rex Zhang
> > > <rexzhang@cienet.com.cn>:
> > >
> > > Hello Eric,
> > >
> > > Thank you Eric. Your example is better and
> > > clear.
> > >
> > > Below is error output when just do:
> > >
> > >
> > > p user.get_attr :whencreated
> > >
> > >
> > >
> > > /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/field_type/date.rb:35:in `decode': undefined method `parse' for Time:Class (NoMethodError)
> > > from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:527:in `decode_field'
> > > from /home/rexzhang/.gem/ruby/gems/active_directory-1.6.0/lib/active_directory/base.rb:554:in `get_attr'
> > > from /home/rexzhang/RubymineProjects/ITI/AccountManagement/ad_create_account.rb:20:in `<top (required)>'
> > > from -e:1:in `load'
> > > from -e:1:in `<main>'
> > >
> > >
> > > Regards,
> > > Rex
> > >
> > >
> > >
> > >
> > > On Fri, 2015-03-27 at 15:26 +0100, Eric MSP > > > > Veith wrote:
> > >
> > > > On Friday 27 March 2015 09:50:16, Rex Zhang <rexzhang@cienet.com.cn> wrote:
> > > > > Thank your Eric.
> > > > >
> > > > > I tried this before. But it seems that not all attributes can be queried
> > > > > such as whencreated and whenchanged.
> > > >
> > > > What happens when you just do
> > > >
> > > > p user.get_attr :whencreated
> > > >
> > > > ?
> > > >
> > > > The missing piece of information is obviously there in the User object.
> > > >
> > > > Btw, why the dance with Object#send? There's #get_attr for your User object;
> > > > you could easily work with that, e.g.
> > > >
> > > > %i(cn displayName whencreated whenchanged).each do |i|
> > > > puts "#{i} => #{user.get_attr i}"
> > > > end
> > > >
> > > > HTH.
> > > > --- Eric
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
>
>
>

--
Rex Zhang <rexzhang@cienet.com.cn>