マイナーでもいいよね??

殆どVB系、でも .NET じゃない VB は知らないよん

目次

Blog 利用状況

書庫

日記カテゴリ

DirectoryAccessクラスに追加した組織単位(OU)関連のメソッド

DirectoryAccess クラスに追加した組織単位(OU)関連のメソッドのコードです。(前回追加したコードはこちら

 

VB

'組織単位(OU)を取得します。

Public Shared Function GetOrganizationalUnits() As IList(Of OrganizationalUnit)

  Dim ous As New List(Of OrganizationalUnit)()

  If CanConnectDomain Then  'ドメインに接続できる時

    Using root = GetRootEntry()   'ルートのDirectoryEntryを取得

      Dim filter = String.Format("(objectCategory={0})", CategoryType.OrganizationalUnit)

      Using searcher As New DirectorySearcher(root, filter)

        Using results = searcher.FindAll()

          For Each res As SearchResult In results

            ous.Add(DirectCast(CreateInstance(res.GetDirectoryEntry()), OrganizationalUnit))

          Next

        End Using

      End Using

    End Using

  End If

  Return ous

End Function

 

'指定した組織単位直下のオブジェクトを取得します。

Friend Shared Function GetStoredDomainObjects(ou As OrganizationalUnit) As List(Of DomainObject)

  Dim objects As New List(Of DomainObject)()

  Using searcher As New DirectorySearcher(ou.Entry)

    searcher.SearchScope = SearchScope.OneLevel

    Using results = searcher.FindAll()

      For Each res As SearchResult In results

        objects.Add(DirectCast(CreateInstance(res.GetDirectoryEntry()), DomainObject))

      Next

    End Using

  End Using

  Return objects.OrderBy(Function(o) o.Name).ToList()

End Function

 

C#

//組織単位(OU)を取得します。

public static IList<OrganizationalUnit> GetOrganizationalUnits()

{

  var ous = new List<OrganizationalUnit>();

  if (CanConnectDomain)    //ドメインに接続できる時

  {

    using (var root = GetRootEntry())    //ルートのDirectoryEntryを取得

    {

      var filter = String.Format("(objectCategory={0})", CategoryType.OrganizationalUnit);

      using (var searcher = new DirectorySearcher(root, filter))

      {

        using (var results = searcher.FindAll())

        {

          foreach (SearchResult res in results)

          {

            ous.Add((OrganizationalUnit)CreateInstance(res.GetDirectoryEntry()));

          }

        }

      }

    }

  }

  return ous;

}

 

//指定した組織単位直下のオブジェクトを取得します。

internal static List<DomainObject> GetStoredDomainObjects(OrganizationalUnit ou)

{

  var objects = new List<DomainObject>();

  using (var searcher = new DirectorySearcher(ou.Entry))

  {

    searcher.SearchScope = SearchScope.OneLevel;

    using (var results = searcher.FindAll())

    {

      foreach (SearchResult res in results)

      {

        objects.Add((DomainObject)CreateInstance(res.GetDirectoryEntry()));

      }

    }

  }

  return objects.OrderBy(o => o.Name).ToList();

}

 

GetStoredDomainObjects メソッドは OrganizationalUnit クラス(VB, C#, 説明)から呼び出されるだけなので内部メソッドにしてます。

メソッド内部の検索については GetOrganizationalUnits メソッドやこれまでの Get~s メソッドと較べて 2つの違いがあります。

1 つは DirectorySearcher コンストラクタ パラメータです。

GetOrganizationalUnits メソッドはドメイン全体で OU を検索するため、検索のルートとなるドメインの DirectoryEntry と検索対象を指定するフィルタ文字列を指定してますが、GetStoredDomainObjects メソッドは その OU 直下のすべてのオブジェクトを検索するので、検索のルートとなる OU の DirectoryEntry を指定してるだけです。

もう 1 つは DirectorySearcher.SearchScope プロパティを指定してることです。

SearchScope.OneLevel を指定することで検索を直下だけにすることができます。

SearchScope プロパティの既定値は SearchScope.Subtree なので、指定しないとサブツリー全体を検索することになります。

投稿日時 : 2014年3月11日 0:21

コメントを追加

# re: DirectoryAccessクラスに追加した組織単位(OU)関連のメソッド 2016/12/23 11:09 kibaya


Pandora Gift Charm http://www.topjewelryonsale.com
Cool Pandora Charms http://www.topjewelrycenter.com
Pandora Latest Charms http://www.topjewelrystar.com
Newest Pandora Charms http://www.topjewelryboutique.com
Replica Michael Kors Wallet http://www.bagsonlineforus.com
Ebay Coach Luggage http://www.bagsluxushow.com
Wholesale Coach Bags http://www.tophandbagstars.com
Coach Backpack For Men http://www.tophandbagzone.com
Large Coach Tote Bags http://www.tophandbagbazaar.com
Coach Euro Purse http://www.tophandbagshow.com

# MwZogdwUqRCWOb 2021/07/03 3:29 https://amzn.to/365xyVY

Superb post here, thought I could learn more from but we can learn more from this post.

# FliNOLKOiXV 2021/07/03 4:58 https://www.blogger.com/profile/060647091882378654

the time to read or check out the content material or websites we ave linked to beneath the

# erectile exercises video 2021/07/08 16:17 hydroxychloroquine treats

hydroxychoriquin https://plaquenilx.com/# risks of hydroxychloroquine

# re: DirectoryAccess????????????(OU)??????? 2021/07/14 21:16 hydroxychloroquine sulfate 200 mg tab

chloroquine tablet https://chloroquineorigin.com/# plaquenil 200 mg twice a day

# nfqcogzvigmc 2021/11/30 10:41 dwedayaqmd

https://chloroquinesbtc.com/

# smkbtnmxdwkv 2022/06/15 16:14 nerlocoh

buy plaquenil online friends program https://hydroxychloroquinex.com/

# chloroquine online 2022/12/26 16:00 MorrisReaks

http://hydroxychloroquinex.com/ generic plaquenil online

# Greetings! I've been following your web site for some time now and finally got the bravery to go ahead and give you a shout out from Humble Texas! Just wanted to mention keep up the good job! 2023/11/16 17:04 Greetings! I've been following your web site for s

Greetings! I've been following your web site for some time
now and finally got the bravery to go ahead and give you a shout out
from Humble Texas! Just wanted to mention keep up the good
job!

# Greetings! I've been following your web site for some time now and finally got the bravery to go ahead and give you a shout out from Humble Texas! Just wanted to mention keep up the good job! 2023/11/16 17:05 Greetings! I've been following your web site for s

Greetings! I've been following your web site for some time
now and finally got the bravery to go ahead and give you a shout out
from Humble Texas! Just wanted to mention keep up the good
job!

# Greetings! I've been following your web site for some time now and finally got the bravery to go ahead and give you a shout out from Humble Texas! Just wanted to mention keep up the good job! 2023/11/16 17:05 Greetings! I've been following your web site for s

Greetings! I've been following your web site for some time
now and finally got the bravery to go ahead and give you a shout out
from Humble Texas! Just wanted to mention keep up the good
job!

# Greetings! I've been following your web site for some time now and finally got the bravery to go ahead and give you a shout out from Humble Texas! Just wanted to mention keep up the good job! 2023/11/16 17:06 Greetings! I've been following your web site for s

Greetings! I've been following your web site for some time
now and finally got the bravery to go ahead and give you a shout out
from Humble Texas! Just wanted to mention keep up the good
job!

タイトル
名前
URL
コメント