SQL Query to get all System discovery containers OU

lalajee 1,821 Reputation points
2022-02-23T11:01:47.883+00:00

Hi,

I need an sql query to get OU list for every primary site within CAS

I have following piwershell script but need sql query to do same

cls

$listAdContainers = (get-cmdiscoveryMethod -name ActiveDirectorySystemDiscovery -sitecode xxx).proplists | where-Object {$_.PropertyListName -eq "AD Containers"}

($listAdContainers.values -like 'ldap*')

Microsoft Security Intune Configuration Manager Other
{count} votes

3 answers

Sort by: Most helpful
  1. Garth Jones 1,666 Reputation points MVP
    2022-02-23T16:14:25.623+00:00
    0 comments No comments

  2. Sherry Kissinger 5,526 Reputation points
    2022-02-23T16:49:01.017+00:00

    I have this from years ago; assume it still works:

    Select
    RV.Netbios_Name0,
    case
    When (Max(OU.System_OU_Name0) != Null or Max(OU.System_OU_Name0) != '')
    Then Max(OU.System_OU_Name0)
    Else max(cn.System_Container_Name0)
    end as 'OU'
    From
    dbo.v_R_System_Valid RV
    left outer join dbo.v_RA_System_SystemContainerName CN on RV.Resourceid = cn.resourceID
    left outer join dbo.v_RA_System_SystemOUName OU on RV.Resourceid = OU.resourceID
    Group by
    RV.Netbios_Name0

    0 comments No comments

  3. AllenLiu-MSFT 49,311 Reputation points Microsoft External Staff
    2022-02-24T07:59:21.157+00:00

    Hi, @lalajee

    Thank you for posting in Microsoft Q&A forum.

    Sherry's query is for checking the OU for each client, it doesn't seem to meet your requirements.
    I tried to find a view to query the AD containers for the Active Direstory System Discovery, but I did not find it.
    I also tried your powershell command, it did query the AD Containers list. Why do you also need the sql query?


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.