从组名称开头的组中删除Active Directory用户

时间:2018-01-31 11:38:23

标签: vb.net active-directory directoryservices account-management

我在尝试克服VB.net中的问题时遇到了麻烦。我想要实现的是从组中名称以“Google”开头的所有组中删除一个特定的AD用户...

如果我知道该组的全名,这是一件简单的事情,我可以做以下事情:

Dim ctx As DirectoryServices.AccountManagement.PrincipalContext = New DirectoryServices.AccountManagement.PrincipalContext(DirectoryServices.AccountManagement.ContextType.Domain, "Company.co.uk")
Dim googleremove As DirectoryServices.AccountManagement.GroupPrincipal = DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(ctx, "Google-Group1")
googleremove.Members.Remove(ctx, DirectoryServices.AccountManagement.IdentityType.SamAccountName, "UserID")
googleremove.Save()

但问题是我的应用程序并不总是知道用户需要从哪个特定组中删除。有28个不同的组,每个组有数千个用户,其中组名称以“Google-”开头。有没有一种有效的方法可以从组中名称以“Google-”开头的所有组中删除用户,这不会让事情变得非常糟糕?

2 个答案:

答案 0 :(得分:1)

我解决了!以下是我为我的问题管理其他人的方式:

<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:component-scan base-package = "com.tutorialspoint" />

   <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name = "prefix" value = "/WEB-INF/jsp/" />
      <property name = "suffix" value = ".jsp" />
   </bean>

</beans>

答案 1 :(得分:0)

您说您知道如何获取MemberOf信息。您是否会遍历该数组以查找以&#34; Google&#34;。

开头的群组

但请记住,MemberOf数组是distinguishedNames数组,因此组名前缀为&#34; CN =&#34;。所以你真的需要做这样的事情:

For Each groupDn as String in memberOf
    If groupDn.StartsWith("CN=Google"))
        //remove user from this group
    End If
Next

我暂时没有使用过VB,所以可能无法正常工作。但这就是想法。

相关问题