SQL Query to get All AD Groups and its users in Active Directory

Hi,
   Is there any query to get all AD groups and its user in an instance of a SQL server?

Check this blog.
http://www.mikefal.net/2011/04/18/monday-scripts-%E2%80%93-xp_logininfo/
It will give you more than what is required. If you dont want the extra information,then you can try this.. I took the query and removed the bits that you might not require.
declare @winlogins table
(acct_name sysname,
acct_type varchar(10),
act_priv varchar(10),
login_name sysname,
perm_path sysname)
declare @group sysname
declare recscan cursor for
select name from sys.server_principals
where type = 'G' and name not like 'NT%'
open recscan
fetch next from recscan into @group
while @@FETCH_STATUS = 0
begin
insert into @winlogins
exec xp_logininfo @group,'members'
fetch next from recscan into @group
end
close recscan
deallocate recscan
select
u.name,
u.type_desc,
wl.login_name,
wl.acct_type
from sys.server_principals u
inner join @winlogins wl on u.name = wl.perm_path
where u.type = 'G'
order by u.name,wl.login_name
Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

Similar Messages

  • SQL Query to get Project Plan Name and Resource Name from Reporting database of Project Server 2007

    Can you please help me to write an SQL Query to get Project Plan Name and Resource Name from Reporting database of Project Server 2007. Thanks!!

    Refer
    http://gallery.technet.microsoft.com/projectserver/Server-20072010-SQL-Get-a99d4bc6
    SELECT
    dbo.MSP_EpmAssignment_UserView.ProjectUID,
    dbo.MSP_EpmAssignment_UserView.TaskUID,
    dbo.MSP_EpmProject_UserView.ProjectName,
    dbo.MSP_EpmTask_UserView.TaskName,
    dbo.MSP_EpmAssignment_UserView.ResourceUID,
    dbo.MSP_EpmResource_UserView.ResourceName,
    dbo.MSP_EpmResource_UserView.ResourceInitials
    INTO #TempTable
    FROM dbo.MSP_EpmAssignment_UserView INNER JOIN
    dbo.MSP_EpmProject_UserView ON dbo.MSP_EpmAssignment_UserView.ProjectUID = dbo.MSP_EpmProject_UserView.ProjectUID INNER JOIN
    dbo.MSP_EpmTask_UserView ON dbo.MSP_EpmAssignment_UserView.TaskUID = dbo.MSP_EpmTask_UserView.TaskUID INNER JOIN
    dbo.MSP_EpmResource_UserView ON dbo.MSP_EpmAssignment_UserView.ResourceUID = dbo.MSP_EpmResource_UserView.ResourceUID
    SELECT
    ProjectUID,
    TaskUID,
    ProjectName,
    TaskName,
    STUFF((
    SELECT ', ' + ResourceInitials
    FROM #TempTable
    WHERE (TaskUID = Results.TaskUID)
    FOR XML PATH (''))
    ,1,2,'') AS ResourceInitialsCombined,
    STUFF((
    SELECT ', ' + ResourceName
    FROM #TempTable
    WHERE (TaskUID = Results.TaskUID)
    FOR XML PATH (''))
    ,1,2,'') AS ResourceNameCombined
    FROM #TempTable Results
    GROUP BY TaskUID,ProjectUID,ProjectName,TaskName
    DROP TABLE #TempTable
    -Prashanth

  • Query to get all ports assigned and used by EBS instance.

    Hi,
    Can some one pleaase help to get
    Query to get all ports assigned and used by EBS instance.
    Help is appreaciated.
    Regards,
    Milan

    MILAN RATHOD wrote:
    Hi,
    Can some one pleaase help to get
    Query to get all ports assigned and used by EBS instance.
    Help is appreaciated.
    Regards,
    MilanIn addition to the thread referenced above by Helios, please check the context files and (Oracle E-Business Suite R12 Configuration in a DMZ [ID 380490.1] -- F. List of Ports to Open in a DMZ Configuration).
    Thanks,
    Hussein

  • How to get list of groups and the users from OID

    Hi,
    Can someone please tell me how to get the list of GROUPS and all the USERS in each group in OID using Java. Need to recursively get all the Groups and Users in each group using Java any samples.
    Thanks

    use examples from OTN like
    http://www.oracle.com/technology/sample_code/products/jdev/readmes/samples/ldapdatacontrol/ldapapplication/src/dc/ldap/model/LDAPSearch.java
    and modify it to your needs
    Bernhard

  • Looking for a SQL query to get all the possible Alert Messages from the Rules in a Management Pack

    For reporting, I'm looking to get a SQL query of all the possible Alert Messages for Rules configured in a Management Pack (not necessarily the ones that have thrown alerts).  I can do this for Monitors, but not for Rules. 
    The configured alert messages for the Management Pack Monitors
    go like this:  ManagementPack > MonitorView> RuleModule > RuleModule.Alert Message > Localized Text
    The configured alert messages for the Management Pack Rules
    should go something like this, but there is a missing link:  ManagementPack > RuleView > RuleModule > ? Missing Link ? > Localized Text
    The Rules are tied to the Module, but I don't see a connection from the RulesModule to the Alert Message that I see in the LocalizedText. The Rule names do not always equal the Alert name. 
    Can someone provide the missing link?

    Hi,
    please try below powershell code to find the corresponding management pack for specific alert:
    $Alert = get-scomalert | where {$_.Name -like 'Agent Proxy Not Enabled*'} | select -first 1
    If ($alert.IsMonitorAlert -eq "True") {
    write-host "Ths is a monitor-generated alert"
    get-scommonitor -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
    else
    write-host "This is a rule-generated alert"
    get-scomrule -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
    In addition, please also refer to the below link:
    http://blogs.technet.com/b/mazenahmed/archive/2011/12/02/using-powershell-to-map-opsmgr-active-alert-to-its-corresponding-rule-monitor-and-management-pack-name.aspx
    Regards,
    Yan Li
    Regards, Yan Li

  • SQL-Query-Question: get all ID2 which have specific ID1

    Hello,
    I have a table Tab1 with millions of entries like
    ID1    ID2
    1       aa
    4       aa
    1       bb
    4       cc
    I'm looking for a sql-query which gives me all ID2-values which have a all of the supplied ID1, in the example above if I query for 1 4 then I want aa and not bb or cc because bb has only 1 and cc only 4.
    The values of ID1 could be a lot like (1,2,3,5,7,8,9,10,34,4,67,33,53,43...).
    Greetings
    Stefan

    just this
    SELECT ID1,ID2
    FROM Table t
    WHERE EXISTS (SELECT 1
    FROM Table
    AND ID2 = t.ID2
    HAVING COUNT(DISTINCT CASE WHEN ID1 IN (1,4) THEN ID1 ELSE NULL END) = 2
    If you want you can pass values 1,4 through a parameter to make it generic like below           
    DECLARE @ValueList varchar(10)
    SET @ValueList = '1,4'
    SELECT ID1,ID2
    FROM Table t
    WHERE EXISTS (SELECT 1
    FROM Table
    WHERE ID2 = t.ID2
    HAVING COUNT(DISTINCT CASE WHEN ',' + @ValueList + ',' LIKE '%,' + CAST(ID1 AS varchar(5)) + ',%' THEN ID1 END) = LEN(@ValueList) - LEN(REPLACE(@ValueList,',','')) + 1
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to get profit center group and its description

    According to three tables(as below), i get profit center group, how to get its description?
    CEPC  (Profit Center Master Data Table)
    SETLEAF
    SETNODE
    PS:(Referrence to teh link fields in table)
    For Profit centre Group ( SETLEAF-SETNAME )
    Select BSEG-BUKRS / BSEG-PRCTR from BSEG.
    SELECT SINGLE SETNAME INTO WA_SETNAME
    FROM SETLEAF
    WHERE SETCALSS = '0106'
    AND SUBCLASS = BSEG-BUKRS
    AND VALFROM = BSEG-PRCTR
    i can get two records, why?

    Hi,
    I am not sure of the significance of this table...
    But looking at the table structure it is having LINEID as one of the key fields..
    So you can have more than one record for the same combination..
    Thanks,
    Naren

  • How to get the name of the selected user in Active Directory.

    Hi,
    I have added an vbs script to the Active Directory GUI, to do some actions on a selected user.
    When I right-click on a AD user, I choose my custom option, and a vbs script starts.
    So far so good, but in the script i would like to know the account (logonname) for that user.
    I can find many examples to do that with a script and a given parameter, but the parameter is in my case, the selected user in AD.
    Who can help ?
    Luc

    You just need to take the arguments and echo out the samaccountname (or do something else with it) - 
    Set wshArgs=WScript.Arguments
    Set adsUser=GetObject(wshArgs(0))
    MsgBox adsUser.samaccountname

  • SQL Query for members of dynamic group - Need to include Name, Path and Type

    Hello,
    I built a custom dynamic group that has all my SQL databases in it using SCOM 2012 SP1.  The group works fine as I can see the Name(ie, Database name), Health State, Path (ie, hostname/instance) and Types (ie; SQL 2005).  Now I'm trying to
    build a custom report based off this same information using a SQL query.   I'm no DBA and could use some help.  So far this is what i have
    use
    select
    SourceObjectDisplayName as
    'Group Name',
    TargetObjectDisplayName,TargetObjectPath
    from RelationshipGenericView
    where isDeleted=0
    AND SourceObjectDisplayName
    like
    'SQL_Databases_All'
    ORDERBY TargetObjectDisplayName
    This gets me the Group Name (which i really don't care about), database name, and hostname/instance. What I am missing is the Health State and most importantly the Type (ie, SQL Server 2005 DB, SQL Server 2008DB).
    If someone could assist me here I would appreciate it. I believe I need to do some type of INNER JOIN but have no idea where the SQL type info lives or the proper structure to use. Thanks
    OperationsManager

    Here's the updated Query for OpsMan 2012 R2:
    To find all members of a given group (change the group name below):
    select SourceObjectDisplayName as 'Group Name', TargetObjectDisplayName as 'Group Members' 
    from RelationshipGenericView 
    where isDeleted=0 
    AND SourceObjectDisplayName = 'Agent Managed Computer
    Group' 
    ORDER BY TargetObjectDisplayName

  • Query for getting all function and procedure inside the packages

    hi All
    Please provide me Query for getting all function and procedure inside the packages
    thanks

    As Todd said, you can use user_arguments data dictionary or you can join user_objects and user_procedures like below to get the name of the packaged function and procedure names.
    If you are looking for the packaged procedures and functions source then use user_source data dictionary
    select a.object_name,a.procedure_name from user_procedures a,
                  user_objects b
    where a.object_name is not null
    and a.procedure_name is not null
    and b.object_type='PACKAGE'        
    and a.object_name=b.object_name

  • SQL query to list all collections, members, OS, SP, IP and if physical/virtual

    Hi guys, I have the below query which lists all the collections and their members, however I need to expand it to also include the OS, Service Pack, IP and if it's a physical or virtual machine.
    I've tried a few things but only made it worse. Is anyone able to expand the below code to include those extras??
    SELECT
    v_FullCollectionMembership.CollectionID AS 'CollID',
    v_Collection.Name AS 'CollName',
    v_FullCollectionMembership.Name AS 'SystemName'
    FROM
    v_FullCollectionMembership, v_Collection
    WHERE v_FullCollectionMembership.CollectionID = v_Collection.CollectionID
    ORDER BY
    CollID ASC, SystemName ASC

    Hi,
    These requirements could be found in several threads or blogs. We need convert WQL to SQL, and you can involve SQL guys to integrate the statements and format the result.
    How to create a all virtual machines collection.
    SCCM SQL Query - IP Address
    ConfigMgr Systems without Current Service Packs, and System Patch Status 

  • SQL query to get DDL for Adding PK.

    Guys,
    I'm looking for SQL query that gets me the "ALTER TABLE <TABLE_NAME> ADD CONSTRAINT <constraint_name> PRIMARY KEY (X,Y,...);" statments of all tables in my schema containing Primary Keys.
    Could someone help me with the query please?
    Regards,
    Bhagat

    You need this
    SELECT 'ALTER TABLE '||table_name||' ADD CONSTRAINT '||constraint_name||' PRIMARY KEY ('||column_name||');'
      FROM ( SELECT uc.table_name
                   ,uc.constraint_name
                   ,RTRIM (XMLAGG (XMLELEMENT (ucc, column_name || ',')).extract ('//text()'), ',')  column_name
              FROM user_constraints        uc
                  ,user_cons_columns       ucc
             WHERE uc.constraint_type      = 'P'
               AND uc.constraint_name      = ucc.constraint_name
          GROUP BY uc.table_name
                  ,uc.constraint_name
    ORDER BY table_name;   Regards
    Arun

  • SQL Query (updateable report) Region - Conditionally Hide and Set Values

    SQL Query (updateable report) Region - Conditionally Hide and Set Values
    Outline of requirement :-
    Master / Detail page with Detail updated on same page using SQL Query (updateable report).
    The detail region has the following source
    SELECT item_id,
           contract_id,
           CASE WHEN hardware_id IS NOT NULL THEN
                   'HA'
                WHEN backup_dev_id IS NOT NULL THEN
                   'BD'
                WHEN hardware_os_id IS NOT NULL THEN
                   'HS'
           END item_type,
           hardware_id,
           backup_dev_id,
           hardware_os_id
    FROM   "#OWNER#".support_items
    WHERE  contract_id = :P26_CONTRACT_IDThe table support_items implements arced relationships and has the following columns
    CREATE TABLE SUPPORT_ITEMS
      ITEM_ID         NUMBER                        NOT NULL,
      CONTRACT_ID     NUMBER                        NOT NULL,
      HARDWARE_ID     NUMBER,
      BACKUP_DEV_ID   NUMBER,
      HARDWARE_OS_ID  NUMBER
    )A check type constaint on support_items ensures that only one of the fk's is present.
          (    hardware_id    IS NOT NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NOT NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NOT NULL
          )    Hardware_Id is a FK to Hardware_Assets
    Backup_dev_id is a FK to Backup_Devices
    Hardware_os_id is a FK to Hardware_op_systems
    The Tabular Form Element based on item_type column of SQL query is Displayed As Select List (based on LOV) referencing a named list of values which have the following properties
    Display Value     Return Value
    Hardware Asset    HA
    Backup Device     BD
    Computer System   HSThe Tabular Form Elements for the report attributes for hardware_id, backup_dev_id and hardware_os_id are all Displayed As Select List (Based on LOV).
    What I want to do is only display the Select List for the FK depending on the value of the Select List on Item Type, e.g.
    Item_Type is 'HA' then display Select List for hardware_id, do not display and set to NULL the Select Lists for backup_dev_id and hardware_os_id.
    Item_Type is 'BB' then display Select List for backup_dev_id, do not display and set to NULL the Select Lists for hardware_id and hardware_os_id.
    Item_Type is 'HS' then display Select List for hardware_os_id, do not display and set to NULL the Select Lists backup_dev_id and hardware_id.
    There are properties on elements to conditionally display it but how do we reference the values of the SQL query Updateable region? they are not given a page item name?
    Also on the Tabular For Elements there is an Edit tick against a report item - however when you go to the Column Attributes there is not a property with which you can control the Edit setting.
    What's the best way of implementing this requirement in APEX 3.1?
    Thanks.

    >
    Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "user13515136".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I have a multi-row region that displays values and allows entries in a number of fields.Provide exact details of how this has been implemented. (An example on apex.oracle.com is always a good way to do this.)
    I should like the fields to be conditional in that they do not permit entry, but still display, if certain conditions apply (e.g. older rows greyed out). Can this be done? Almost anything can be done, often in multiple ways. Which are appropriate may be dependent on a particular implementation, the skills available to implement it, and the effort you're willing to expend on it. Hence it's necessary to provide full details of what you've done so far...

  • Oracle query to get all occurences of a text in a string

    Hi
    Does anybody know how to write a query to get all occurences of a text in a string in different rows of the table
    For eg:
    I have a string <aa>bb</aa><aa>cc</aa><aa>ddd</aa>
    I have to find every occurence of <aa> and get the data between <aa> and </aa>
    So the output should be
    bb
    cc
    ddd
    I think this can be done by using a regular expression but I dont know how.
    Can anyone help me?
    Thanks in advance.

    user2360027 wrote:
    BluShadow,
    The query gives correct results if i only have <aa></aa>
    What if i have <ff></ff>?
    Example:
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa><ff>dsd</ff>
    I want to have the following (dsd should not be there in the result)
    bb
    cc
    dddThis is a new requirement and not what you asked for in your original post. Perhaps you should tell us exactly what you are trying to achieve and what database version you are using to save us guessing.
    To crokitta,
    This version will deal with multiple rows..
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select '<aa>bb</aa><aa>cc</aa><aa>ddd</aa>' as x from dual union all
      2             select '<aa>xx</aa><aa>yy</aa>' from dual)
      3  -- end of test data
      4  select x, vals
      5  from (
      6    select x, regexp_replace(REGEXP_SUBSTR (x, '>[^<]+', 1, lvl),'[<>]') as vals
      7    from t
      8        ,(select level lvl from dual connect by level <= (select max(length(regexp_replace(x,'[^>]*'))/2) from t))
      9    )
    10  where vals is not null
    11* order by 1,2
    SQL> /
    X                                  VALS
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> bb
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> cc
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> ddd
    <aa>xx</aa><aa>yy</aa>             xx
    <aa>xx</aa><aa>yy</aa>             yy
    SQL>

  • SQL query to get a list of relations between workitems

    How can I create a SQL query to get a list of all problems with related changes?  And all problems with related incidents?
    I have tried to join the tables RelationshipTypeDim with ProblemDimKey and ChangeRequestDim, but the results are not correct.

    The relationships in the data warehouse can be kind of tricky. The relationships are contained in the WorkItemRelatesToWorkItemFactvw table. This table lists the related items by their WorkItemDimKey, so you cannot reference directly from the ChangeRequestDimvw
    or ProblemDimvw. You will need to reference the WorkItemDimvw to get the WorkItemDimKey for each entry.
    The query below will get all of the related work items from the Change Request class. The way the joins work is ChangeRequestDimvw gets the list of change requests. Then inner joins WorkItemDimvw to get the WorkItemDimKey for each CR. Then inner joins WorkItemRelatesToWorkItemFactvw
    to get all of the CRs with related work items. Then inner joins the WorkItemDimvw again to get the ID of the related work item. 
    Now the tricky part is it appears that these relationship are set based on which item  that created the relationship. So you need to union a second query that reverse the relationship on the WorkItemRelatesToWorkItemFactvw. 
    This query should give you a good start on getting the related work items. You can filter it down from here if you only want to include problems.
    SELECT C.ID, WIWI.ID
    FROM dbo.ChangeRequestDimvw C
    INNER JOIN dbo.WorkItemDimvw WI ON
    WI.EntityDimKey = C.EntityDimKey
    INNER JOIN dbo.WorkItemRelatesToWorkItemFactvw AS WIRWI ON
    WIRWI.WorkItemDimKey = WI.WorkItemDimKey
    INNER JOIN dbo.WorkItemDimvw AS WIWI ON
    WIWI.WorkItemDimKey = WIRWI.WorkItemRelatesToWorkItem_WorkItemDimKey
    union
    SELECT C.ID, WIWI.ID
    FROM dbo.ChangeRequestDimvw C
    INNER JOIN dbo.WorkItemDimvw WI ON
    WI.EntityDimKey = C.EntityDimKey
    INNER JOIN dbo.WorkItemRelatesToWorkItemFactvw AS WIRWI ON
    WIRWI.WorkItemRelatesToWorkItem_WorkItemDimKey = WI.WorkItemDimKey
    INNER JOIN dbo.WorkItemDimvw AS WIWI ON
    WIWI.WorkItemDimKey = WIRWI.WorkItemDimKey
    Order by C.ID
    Matthew Dowst |
    Blog | Twitter

Maybe you are looking for

  • Missing characters with menu drop down

    I have witnessed today a very strange problem. We have 2 new G5's (less than 6 months old)running 10.4.6. On both machines today I saw problems with missing characters. On one machine I was reinstalling Adobe CS2 Premium and the initial installation

  • Program monitor changes size when Motion controls change. Turn this off please?

    Hi. I'm running Premiere Pro CC on a fairly new (~6 mo old) iMac with 16 GB ram, SSD, Mavericks, the works. Everything's been great so far. However, I'm having an issue whenever I use the Motion Effect Controls in the Program monitor/timeline. Any ti

  • I can't update Aperture 2 to Aperture 3 (Maverick)

    Hallo, I'd like update Aperture from ver. 2 to 3, for free. I have OS Maverick and Aperture 2 BOX (not purchased by App Store). Unfortunately, when I check updates not show Aperture... I can download upadate Pages, Number etc., but Aperture not. I re

  • Copying Verity Collection

    Since my shared hosting provider has the timeout set so low I can't index my verity collection of pdf files before it times out. So, I'm told I can index it locally, then FTP the index/collection up to my site at the hosting provider. But when I do t

  • Event from message

    Is it possible to make an event in iCal from a message from Mail.app ?