2012-02-21 5 views
4

だから、今日私は、すべてのDLからドメイン内のすべての元従業員を削除する作業を割り当てられました。これをすばやく行う方法はありますか、それぞれを個別にチェックし、すべてのメンバーを削除するよりも早く行うのは簡単ですか?すべての従業員をすべての配布グループから削除します

おかげでより多くの情報を追加する

編集:

が必要822人のユーザーがいるタブ「のメンバーは、」すべての配布リストから削除するように更新します。これは私のチームが5分の1(ヘルプデスク)の約1週間ですでに巨大な作業負荷の上に目を通すでしょう。すべての元従業員とフォルダへのラフなパスは、次のとおりです。ユーザーは、元従業員が、他の情報が必要な場合は

\私はそれを提供することよりも幸せだろう\

BusinessName.local \てMyBusiness \。

編集2:システムに250以上のDLがあるため、機密性と機能性の理由からリストを提供することはできません。

+0

これを手動でUIをクリックするか、プログラムでコードを記述して行いますか?その場合:どの言語/環境ですか? –

+0

チェック/整理する必要がある822人のユーザーがいるので、私はむしろ自動化された方法でそれをやりたいのです。手作業では時間がかかりすぎます。それがUIを介して行われていて、何らかの形式のバルクユーザー管理を行っているか、スクリプトを介していてもどちらも問題ありません。 – HunderingThooves

答えて

3

追加したスクリプト あなたがここにPowerShellスクリプトを使用する場合は.NET用

Add-Type -AssemblyName System.DirectoryServices.AccountManagement 

$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher 
$directorySearcher.SearchRoot = "LDAP://OU=YourOU,DC=YourDomain,DC=com" 
$directorySearcher.PageSize = 1000 
$directorySearcher.Filter = "(&(objectCategory=User))" 
$directorySearcher.SearchScope = "Subtree" 

$directorySearcher.PropertiesToLoad.Add("name") 

$searchResults = $directorySearcher.FindAll() 

foreach ($result in $searchResults) 
{$objItem = $result.Properties 
    "Name: " + $objItem.name 

    $contextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain 
    $userPrincipal = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($contextType,$objItem.name) 
    $userGroups = $userPrincipal.GetGroups() 

    foreach($userGroup in $userGroups){ 
     if ($userGroup.IsSecurityGroup -eq 0) #Distribution Group Only 
     { 
     "Removing - " + $userGroup.SamAccountName 
     $userGroup.Members.Remove($userPrincipal) 
     $userGroup.Save() 
     } 
    } 
} 

コードはここにコード

using System; 
using System.Collections; 
using System.Linq; 
using System.Text; 
using System.DirectoryServices; 
using System.DirectoryServices.AccountManagement; 

namespace RemoveFromDistributionGroups 
{ 
    class Program 
    { 
     private static string sDomain; 
     private static string sDefaultOU; 
     private static string sServiceUser; 
     private static string sServicePassword; 

     static void Main(string[] args) 
     { 
      try 
      { 
       Console.Write("Type your Domain (i.e: yourcompany.com) "); 
       sDomain = Console.ReadLine(); 

       Console.Write("Type the OU you want to use: (i.e: OU=yourou,DC=yourcompany,DC=com)"); 
       sDefaultOU = Console.ReadLine(); 

       Console.Write(@"Username: (i.e.: YOURDOMAIN\Raymund)"); 
       sServiceUser = Console.ReadLine(); 

       Console.Write("Password: "); 
       sServicePassword = Console.ReadLine(); 


       foreach (UserPrincipal user in GetAllUsers()) 
       { 
        Console.WriteLine("Processing User : " + user.Name); 
        foreach (GroupPrincipal group in GetUserGroups(user)) 
        { 
         if (group.IsSecurityGroup == false) //Distribution Group 
         { 
          group.Members.Remove(user); 
          group.Save(); 
         } 
        } 
       } 

       Console.WriteLine("Done! Press a key to exit"); 
       Console.ReadLine(); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine("Error Encountered : " + ex.Message); 
       Console.WriteLine("Press a key to exit"); 
       Console.ReadLine(); 
      } 
     } 
     public static PrincipalContext GetPrincipalContext(string sOU) 
     { 
      PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sOU, ContextOptions.Negotiate, sServiceUser, sServicePassword); 
      return oPrincipalContext; 
     } 
     public static ArrayList GetAllUsers() 
     { 
      ArrayList myItems = new ArrayList(); 
      PrincipalSearcher oPrincipalSearcher = new PrincipalSearcher(); 


      UserPrincipal oUserPrincipal = new UserPrincipal(GetPrincipalContext(sDefaultOU)); 

      oUserPrincipal.SamAccountName = "*"; 
      oUserPrincipal.Enabled = true; 

      oPrincipalSearcher.QueryFilter = oUserPrincipal; 
      ((DirectorySearcher)oPrincipalSearcher.GetUnderlyingSearcher()).PageSize = 5000; 

      PrincipalSearchResult<Principal> oPrincipalSearchResults = oPrincipalSearcher.FindAll(); 
      foreach (Principal oResult in oPrincipalSearchResults) 
      { 
       myItems.Add(oResult); 
      } 

      return myItems; 
     } 
     public static ArrayList GetUserGroups(UserPrincipal oUserPrincipal) 
     { 
      ArrayList myItems = new ArrayList(); 

      PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups(); 

      foreach (Principal oResult in oPrincipalSearchResult) 
      { 
       myItems.Add(oResult); 
      } 
      return myItems; 

     } 

    } 
} 

ですまた$directorySearcher.SearchRootまたはsDefaultOUであることに注意てくださいあなたはあなたの元従業員がどこにあるOU(またはあなたがフォルダと呼ぶもの)を使用する必要があります、私はあなたのケースでは、それが、PowershellまたはNETコードで使用されている場合は210です。

関連する問題