Chinaunix首页 | 论坛 | 博客
  • 博客访问: 469681
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-04-22 10:52:18

首先是adsi的属性使用hash表的方式来设置或者获取;另外一个是注意有的属性有点不一样,需要 设置hash的hash,例如$objCommand -> Properties -> {"Page Size"} = 1000;这里。假设域为microsoft,完整的代码如下:
代码:

use warnings;
use strict;
use Win32::OLE;

use constant ADS_UF_ACCOUNTDISABLE => 2;
use constant ADS_SCOPE_SUBTREE => 2;

my $objConnection = Win32::OLE->new( "ADODB.Connection" );
my $objCommand = Win32::OLE->new( "ADODB.Command" );

# open ad
$objConnection -> open( "Provider=ADsDSOObject;" );

$objCommand -> = $objConnection;

# search what and how
$objCommand -> = "select userAccountControl,distinguishedName from 'GC://dc=china,dc=microsoft,dc=com' where objectCategory='user'";

# import all users
$objCommand -> Properties -> {"Page Size"} = 1000;
# search all subtree
$objCommand -> Properties -> = ADS_SCOPE_SUBTREE;

my $objRecordSet = Win32::OLE->new( "ADODB.Recordset" );
$objRecordSet = $objCommand->Execute( ) || die "query data from active directory error,exit\n";

while( not $objRecordSet -> eof )
{
    my $intUAC = $objRecordSet -> Fields("userAccountControl") -> value;
    
    # remove diable account
    if( not ( $intUAC & ADS_UF_ACCOUNTDISABLE ) )
    {
        my $longName = $objRecordSet -> Fields("distinguishedName") -> value;

        if( $longName =~ /^CN=([\w\.\-\_]+),/ )
        {
            print ."\n";
        }
    }
    
    $objRecordSet -> MoveNext();
}



2.
阅读(598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~