次の方法で共有


グループの作成

ここでは、いくつかの種類のグループの作成方法について説明します。

新しいグループを作成するときは、ADS_GROUP_TYPE_ENUM 列挙体のフラグを使用して、グループの種類をグループに割り当てることができます。たとえば、グローバル (ADS_GROUP_TYPE_GLOBAL_GROUP)、ドメイン ローカル (ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP)、ローカル (ADS_GROUP_TYPE_LOCAL_GROUP)、ユニバーサル (ADS_GROUP_TYPE_UNIVERSAL_GROUP)、セキュリティが有効 (ADS_GROUP_TYPE_SECURITY_ENABLED) などです。グループの種類を指定しない場合、既定ではグローバルで、セキュリティが有効なグループ (ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP | ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED) が作成されます。ADS_GROUP_TYPE_ENU 列挙体の詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で ADS_GROUP_TYPE_ENUM に関する情報を参照してください。

次の Visual Basic .NET のコード例は、Practice Managers という新しいグループを Consulting という組織単位に作成する方法を示しています。ドメインでは、sAMAccountName 属性は必須ですが、Windows Server 2003 またはそれ以降のドメインでは、sAMAccountName 属性はオプションです。sAMAccountName 属性の詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で sAMAccountName または SAM-Account-Name 属性に関する情報を参照してください。

' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()

' Find the container (in this case, the Consulting organizational unit) that you 
' wish to add the new group to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")

' Add the new group Practice Managers.
Dim group As DirectoryEntry = ou.Children.Add("CN=Practice Managers", "group")

' Set the samAccountName for the new group.
group.Properties("samAccountName").Value = "pracmans"

' Commit the new group to the directory.
group.CommitChanges()

次の C# のコード例は、Practice Managers という新しいグループを Consulting という組織単位に作成する方法を示しています。ドメインでは、sAMAccountName 属性は必須ですが、Windows Server 2003 またはそれ以降のドメインでは、sAMAccountName 属性はオプションです。sAMAccountName 属性の詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で sAMAccountName または SAM-Account-Name 属性に関する情報を参照してください。

// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();

// Find the container (in this case, the Consulting organizational unit) that you 
// wish to add the new group to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");

// Add the new group Practice Managers.
DirectoryEntry group = ou.Children.Add("CN=Practice Managers", "group");

// Set the samAccountName for the new group.
group.Properties["samAccountName"].Value = "pracmans";

// Commit the new group to the directory.
group.CommitChanges();

次の Visual Basic .NET のコード例は、Managers というローカル ドメイン グループを Consulting 組織単位に作成する方法を示しています。ADSI にアクセスするための COM 相互運用機能の使用を使用して、ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP フラグを指定します。

' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()

' Find the container (in this case, the Consulting organizational unit) that you 
' wish to add the new local domain group to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")

' Add the Managers group.
Dim mgr As DirectoryEntry = ou.Children.Add("CN=Managers", "group")

' Set the group type to a secured domain local group.
mgr.Properties("groupType").Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP Or ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED

' Commit the new group to the directory.
mgr.CommitChanges()

次の C# のコード例は、Managers というローカル ドメイン グループを Consulting 組織単位に作成する方法を示しています。ADSI にアクセスするための COM 相互運用機能の使用を使用して、ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP フラグを指定します。

// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();

// Find the container (in this case, the Consulting organizational unit) that you 
// wish to add the new local domain group to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");

// Add the Managers group.
DirectoryEntry mgr = ou.Children.Add("CN=Managers", "group");

// Set the group type to a secured domain local group.
mgr.Properties["groupType"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP | 
ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED;

// Commit the new group to the directory.
mgr.CommitChanges();

次の Visual Basic .NET のコード例は、Full Time Employees という配布リストである非セキュリティ グループを Consulting 組織単位に作成する方法を示しています。ADSI にアクセスするための COM 相互運用機能の使用を使用して、ADS_GROUP_TYPE_GLOBAL_GROUP フラグを指定します。

' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()

' Find the container (in this case, the Consulting organizational unit) that you
' wish to add the Full Time Employees distribution list to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")

' Add the Full Time Employees distribution list.
Dim dl As DirectoryEntry = ou.Children.Add("CN=Full Time Employees", "group")

' Set the group type to global.
dl.Properties("groupType").Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP

' Commit the new group to the directory.
dl.CommitChanges()

次の C# のコード例は、Full Time Employees という配布リストである非セキュリティ グループを Consulting 組織単位に作成する方法を示しています。ADSI にアクセスするための COM 相互運用機能の使用を使用して、ADS_GROUP_TYPE_GLOBAL_GROUP フラグを指定します。

// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();

// Find the container (in this case, the Consulting organizational unit) that you
// wish to add the Full Time Employees distribution list to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");

// Add the Full Time Employees distribution list.
DirectoryEntry dl = ou.Children.Add("CN=Full Time Employees", "group");

// Set the group type to global.
dl.Properties["groupType"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP;

// Commit the new group to the directory.
dl.CommitChanges();

次の Visual Basic .NET のコード例は、1 つのグループ全体を別のグループに追加する方法を示しています。

' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()

' Find the container (in this case, the North America group) that you
' wish to add.
Dim group As DirectoryEntry = dom.Children.Find("CN=North America")

' Connect to the group that you wish to add "group" to.
Dim mgr As New DirectoryEntry("LDAP://CN=Managers,OU=Consulting,DC=Fabrikam,DC=COM")

' Add the distinguishedName of "group" to the members property of "mgr".
mgr.Properties("member").Add(group.Properties("distinguishedName").Value)

' Commit the changes to the directory.
mgr.CommitChanges()

次の C# のコード例は、1 つのグループ全体を別のグループに追加する方法を示しています。

// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();

// Find the container (in this case, the North America group) that you
// wish to add.
DirectoryEntry group = dom.Children.Find("CN=North America");

// Connect to the group that you wish to add "group" to.
DirectoryEntry mgr = new DirectoryEntry("LDAP://CN=Managers,OU=Consulting,DC=Fabrikam,DC=COM");

// Add the distinguishedName of "group" to the members property of "mgr".
mgr.Properties["member"].Add(group.Properties["distinguishedName"].Value);

// Commit the changes to the directory.
mgr.CommitChanges();

関連項目

リファレンス

System.DirectoryServices

概念

グループ管理
ADSI にアクセスするための COM 相互運用機能の使用

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.