枚举管理员组(AD)的成员 [英] Enumerate members of Administrators Group (AD)

查看:106
本文介绍了枚举管理员组(AD)的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我找到了这个方便的脚本,我正在尝试将其转换为VB.NET。它会弹出Administrators / Builtin组中的成员列表。
不能

似乎让DirectorySearcher或DirectoryEntry的工作类似于

这个。将其作为VBS脚本运行以查看:


选项显式

Dim strUser,strMember,strDNSDomain,strContainer

Dim objGroup, objUser,objRootDSE

Dim arrMemberOf


''绑定到Active Directory''

strContainer =" cn =管理员,cn =内置,

设置objRootDSE = GetObject(" LDAP:// RootDSE")

strDNSDomain = objRootDSE.Get(" DefaultNamingContext")


''获取内置管理员组

设置objGroup = GetObject(" LDAP://"& strContainer& strDNSDomain)

objGroup.getInfo


arrMemberOf = objGroup.GetEx(" member")


''Loop = For Each .... Next

WScript.EchoGroup of Members &安培; strContainer

每个strrmber在arrMemberOf

WScript.echo strMember

下一页


Wscript.Quit


感谢您的帮助!

解决方案

导入System.DirectoryServices

导入System.Diagnostics

导入System.Runtime.InteropServices

导入ActiveDs


私有子cmdQuery_Click(ByVal发送者)作为System.Object,ByVal e As

System.EventArgs)处理cmdQuery.Click

Dim objMembers As Object = Nothing

Dim collMembers as IADsMembers = Nothing

Dim iadsMember作为IADsUser

Dim strServerName As String


Dim de As New DirectoryEntry()

尝试

strServerName =" SERVER"

de.Username =" Username"

de.Password =" Password"

de.AuthenticationType = AuthenticationTypes.Secure

de.Path =" LDA警://" &安培; strServerName& / CN =域名

管理员,CN =用户,DC =域名,DC =本地


''调用本机方法"

objMembers = de.Invoke(" Members")

collMembers = CType(objMembers,IADsMembers)

collMembers.Filter =" user"

For each iadsMember in collMembers

Debug.WriteLine(" Name ="& iadsMember.Name)

Next


Catch ex As COMException

Debug.WriteLine(" ** Exception **"& vbCrLf& ex.ToString)

结束尝试

结束子

-

使用KJM获取功能强大的网络,数据库,应用程序和电子邮件托管

解决方案
http://www.kjmsolutions.com


" BH Jodo Kast" <是************** @ yahoo.com>在消息中写道

news:11 ********************** @ t39g2000cwt.googlegr oups.com ...



我找到了这个方便的脚本,我正在尝试将其转换为VB.NET。它会弹出Administrators / Builtin组中的成员列表。似乎无法使DirectorySearcher或DirectoryEntry与
类似。将其作为VBS脚本运行以查看:

选项显式
Dim strUser,strMember,strDNSDomain,strContainer
Dim objGroup,objUser,objRootDSE
Dim arrMemberOf
''绑定到Active Directory''
strContainer =" cn = Administrators,cn = Builtin,"
设置objRootDSE = GetObject(" LDAP:// RootDSE")
strDNSDomain = objRootDSE.Get(" DefaultNamingContext")
''获取内置管理员组
设置objGroup = GetObject(" LDAP://"& strContainer& ; strDNSDomain)
objGroup.getInfo

arrMemberOf = objGroup.GetEx(" member")

''Loop = For Each .... Next
每个strrmber在arrMemberOf
WScript.echo strMember
下一页

Wscript.Quit

感谢您的帮助!


无法找到导入ActiveDs的命名空间或类型''ActiveDs'

类型未定义的IADs成员

类型IADsUsers未定义


什么是ActiveDs?


Interop.ActiveDs


我添加了这个COM引用。这是Active DS IIS名称空间

提供商在Visual Studio中。


Hi,

I found this handy script and I''m trying to convert it to VB.NET. It
pops up a list of members in the Administrators/Builtin group. Can''t
seem to get DirectorySearcher or DirectoryEntry working similar to
this. Run this as a VBS script to see:

Option Explicit
Dim strUser, strMember, strDNSDomain, strContainer
Dim objGroup, objUser, objRootDSE
Dim arrMemberOf

'' Bind to Active Directory''
strContainer = "cn=Administrators,cn=Builtin, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

'' Get the Builtin Administrators group
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf = objGroup.GetEx("member")

'' Loop = For Each .... Next
WScript.Echo "Members of Group " & strContainer
For Each strMember in arrMemberOf
WScript.echo strMember
Next

Wscript.Quit

Thanks for your help!

解决方案

Imports System.DirectoryServices
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports ActiveDs

Private Sub cmdQuery_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdQuery.Click
Dim objMembers As Object = Nothing
Dim collMembers As IADsMembers = Nothing
Dim iadsMember As IADsUser
Dim strServerName As String

Dim de As New DirectoryEntry()
Try
strServerName = "SERVER"
de.Username = "Username"
de.Password = "Password"
de.AuthenticationType = AuthenticationTypes.Secure
de.Path = "LDAP://" & strServerName & "/CN=Domain
Admins,CN=Users,DC=DomainName,DC=local"

'' Invoke native method "members"
objMembers = de.Invoke("Members")
collMembers = CType(objMembers, IADsMembers)
collMembers.Filter = "user"
For Each iadsMember In collMembers
Debug.WriteLine("Name = " & iadsMember.Name)
Next

Catch ex As COMException
Debug.WriteLine("**Exception**" & vbCrLf & ex.ToString)
End Try
End Sub
--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"BH Jodo Kast" <be**************@yahoo.com> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com...

Hi,

I found this handy script and I''m trying to convert it to VB.NET. It
pops up a list of members in the Administrators/Builtin group. Can''t
seem to get DirectorySearcher or DirectoryEntry working similar to
this. Run this as a VBS script to see:

Option Explicit
Dim strUser, strMember, strDNSDomain, strContainer
Dim objGroup, objUser, objRootDSE
Dim arrMemberOf

'' Bind to Active Directory''
strContainer = "cn=Administrators,cn=Builtin, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

'' Get the Builtin Administrators group
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf = objGroup.GetEx("member")

'' Loop = For Each .... Next
WScript.Echo "Members of Group " & strContainer
For Each strMember in arrMemberOf
WScript.echo strMember
Next

Wscript.Quit

Thanks for your help!



Namespace or Type ''ActiveDs'' for Imports ActiveDs cannot be found
Type IADsMembers not defined
Type IADsUsers not defined

What''s ActiveDs?


Interop.ActiveDs

I added this COM reference. It''s the "Active DS IIS Namespace
Provider" in Visual Studio.


这篇关于枚举管理员组(AD)的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆