首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PowerShell查询eDirectory

使用PowerShell查询eDirectory
EN

Stack Overflow用户
提问于 2015-12-25 15:05:15
回答 1查看 3.7K关注 0票数 1

我有工作VBScript搜索eDirectory

代码语言:javascript
复制
Set dso = GetObject("LDAP:")
Dim pwd
pwd = "NotTellingU!"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider", "cn=x12345,ou=IDM,ou=System,o=XYZ" , pwd

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://myservq01.myplace.corp/o=XYZ>;" & _
    "(ou=*)" & ";" & "ou;onelevel"

Set objRecordSet = objCommand.Execute
WScript.Echo objRecordSet.RecordCount

试图在PowerShell (V2)中实现这一点:

代码语言:javascript
复制
[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.Protocols") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Net") | Out-Null

$BaseDN = "o=XYZ"
$attrlist = "ou"
$scope = [System.DirectoryServices.Protocols.SearchScope]::OneLevel
$Filter = "(ou=*)"

$c = New-Object System.DirectoryServices.Protocols.LdapConnection "myservq01.myplace.corp:389"
$c.SessionOptions.SecureSocketLayer = $FALSE;
$c.AuthType = [System.DirectoryServices.Protocols.AuthType]::Basic

$user = "cn=x12345,ou=IDM,ou=System,o=XYZ"
$pwd = "NotTellingU!"
$NovellCredentials = New-Object "System.Net.NetworkCredential" -ArgumentList $user,$pwd
$c.Credential = $NovellCredentials
$c.Bind()
$r = New-Object System.DirectoryServices.Protocols.SearchRequest -ArgumentList  $baseDN,$Filter,$scope,$attrlist
$re = $c.SendRequest($r);
"A Total of $($re.Entries.Count) Entry(s) found in LDAP Search"

在执行绑定和SendRequest的两行中,我得到了

使用"0“参数调用"Bind”的异常:“所提供的凭据无效。”

我对两者都做了NDS的检测。在VBScript中,它是:

代码语言:javascript
复制
LDAP: New cleartext connection 0x2006dc70 from 123.45.211.222:58720, monitor = 0x85f45700, index = 17
LDAP: (123.45.211.222:58720)(0x0001:0x60) DoBind on connection 0x2006dc70
LDAP: (123.45.211.222:58720)(0x0001:0x60) Bind name:cn=x12345,ou=IDM,ou=System,o=XYZ, version:3, authentication:simple

LDAP: (123.45.211.222:58477)(0x0005:0x63) DoSearch on connection 0x2006dc70
LDAP: (123.45.211.222:58477)(0x0005:0x63) Search request:
   base: "o=XYZ"
   scope:1 dereference:0 sizelimit:0 timelimit:0 attrsonly:0
   filter: "(ou=*)"
   attribute: "ou"
LDAP: (123.45.211.222:58477)(0x0005:0x63) Sending search result entry "ou=services,o=XYZ" to connection 0x2006dc70

来自PS:

代码语言:javascript
复制
LDAP: New cleartext connection 0x2006dc70 from 123.45.211.222:59552, monitor = 0x85f45700, index = 17
LDAP: (123.45.211.222:59552)(0x0007:0x60) DoBind on connection 0x2006dc70
LDAP: (123.45.211.222:59552)(0x0007:0x60) Bind name:cn=x12345,ou=IDM,ou=System,o=XYZ, version:2, authentication:simple
LDAP: (123.45.211.222:59552)(0x0007:0x60) Failed to authenticate local on connection 0x2006dc70, err = failed authentication (-669)
LDAP: (123.45.211.222:59552)(0x0007:0x60) Sending operation result 49:"":"NDS error: failed authentication (-669)" to connection 0x2006dc70

我唯一能看到的区别是在Bind name行上。当它开始工作时,我看到了"version:3“,当它失败时,"version:2",但是我还没有在代码中找到任何可以控制它的方法。

EN

回答 1

Stack Overflow用户

发布于 2015-12-28 17:42:00

我不明白这会有什么不同,但是在$user和$pwd变量周围使用单引号似乎可以让它工作:

$user = 'cn=x12345,ou=IDM,ou=System,o=XYZ‘$pwd =NotTellingU!

这个URL帮助了https://social.technet.microsoft.com/Forums/scriptcenter/en-US/d1c4fc40-b921-4840-9d98-d95d565672d1/queryenumerate-edirectory-in-powershell-via-systemdirectoryservices?forum=ITCG

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34463904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档