perl - 如何从 Perl 使用 Active Directory?

标签 perl active-directory ldap

我正在考虑编写一些与 Active Directory 交互的 Perl 脚本。作为 Perl 的新手,我想知道是否有任何人会建议我使用的特定模块、工具、技术等。截至目前,我只想提取用户信息以使用脚本进行处理。

最佳答案

Active Directory的最佳来源example code in Perl is available here .来自 O'Reilly 的优秀 Active Directory Cookbook 的合著者 Robbie Allen .

Here is an example从他们的食谱代码:

# This Perl code finds all disabled user accounts in a domain.

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Active Directory Cookbook" by Robbie Allen
# ISBN: 0-596-00466-4
# ---------------------------------------------------------------

# ------ SCRIPT CONFIGURATION ------
my $strDomainDN = "<DomainDN>";    # e.g. dc=rallencorp,dc=com
# ------ END CONFIGURATION ---------
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $strBase   =  "<LDAP://" . $strDomainDN . ">;";
my $strFilter = "(&(objectclass=user)(objectcategory=person)" . 
                "(useraccountcontrol:1.2.840.113556.1.4.803:=2));";
my $strAttrs  = "name;";
my $strScope  = "subtree";

my $objConn = Win32::OLE->CreateObject("ADODB.Connection");
$objConn->{Provider} = "ADsDSOObject";
$objConn->Open;
my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope);
$objRS->MoveFirst;
while (not $objRS->EOF) {
    print $objRS->Fields(0)->Value,"\n";
    $objRS->MoveNext;
}

关于perl - 如何从 Perl 使用 Active Directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1526028/

相关文章:

perl - IO::Socket 服务器和 POST 数据的小问题

perl - 在 Perl 中,为什么我需要 Exporter?

ASP.NET C# Active Directory - 查看用户密码过期还有多长时间

rest - 访问 Azure Active Directory 用户和角色

Java:寻找一个库来读取 LDAP 数据

python - 如何在python中重置普通ldap用户的密码而无需旧密码?

windows - 使用 Parallel::ForkManager 发出警告,但仅在 Windows 中

regex - 识别哈希键的 "type"

C# Active Directory,登录特定的 OU

交响乐 5 : ldap authentication with custom user entity