XRMTOOLBOX SQL 4 CDS to get logged in users, Users with security roles in Dynamics 365

User Review
0 (0 votes)

Hello Everyone,

Today i am going to show the XRMTOOLBOX tool SQL 4 CDS which allows you to use standard SQL  syntax to query and manipulate your data and metadata in Dataverse and Dynamics 365.

Let’s gets started.
Here is the link for sql 4 cds 

SQL 4 CDS tool Capabilities:
First of all many thanks to creator of this tool Mark Carrington.
As per the release notes:
Add support for XML data type and FOR XML clause.

Add support for Elastic tables

Add support for Stuff function

Add option to bypass plugins for SELECT statements

Improved error reporting for duplicated table/alias names

Improved error reporting for plugin errors

Improved efficiency of joins that can’t be translated to FetchXML

Improved error handling during bulk DML Operations

Fixed querying audit table

Fixed Collation label for metadata and virtual columns

Fixed hash joins on different collations

Fixed filtering on outer-joined solution table

Fixed multi threading error with partitioned aggregations

Fixed copying results with headers but no data rows. 

I have used this tool for find out the users with role, below is the script:
SELECT identityid,
FROM   systemuserroles
       systemuser AS systemuser
       ON systemuser.systemuserid = systemuserroles.systemuserid
          AND (systemuser.isdisabled = 0
               AND systemuser.accessmode = 0)
       account AS account
       ON account.accountid = systemuser.gmr_opcoid
       businessunit AS businessunit
       ON businessunit.businessunitid = systemuser.businessunitid
       role AS role
       ON role.roleid = systemuserroles.roleid
          AND (role.name = ‘ Admin All’
            OR role.name = ‘ Admin Owned’
            OR role.name = ‘ Admin Project’
            OR role.name = ‘ Analytics’
            OR role.name = ‘ Basic ‘
            OR role.name = ‘ Basic Client’
            OR role.name = ‘ BI Integration’
            OR role.name = ‘  Embedded Power BI Report’
            OR role.name = ‘ Embedded Reports OC’
            OR role.name = ‘ Financial Controller’
            OR role.name = ‘ Import/Export’
            OR role.name = ‘Integration’
            OR role.name = ‘ Admin’
            OR role.name = ‘ Manager’
            OR role.name = ‘ Integration’
            OR role.name = ‘ Service Account’);

Also for last logged in users:
SELECT   a.actionname,
         a.objectid AS systemuserid,
       (SELECT   TOP 1 c.createdon
          FROM     audit AS c
                   INNER JOIN
                   systemuser AS systemuser
                   ON systemuser.systemuserid = c.objectid
                      AND c.action = 64
                      AND c.createdon >= dateadd(month, -6, GETDATE())
          WHERE    c.objectid = a.objectid
          ORDER BY c.createdon DESC) AS lastloginutc
FROM     audit AS a
         systemuser AS s
         ON a.objectid = s.systemuserid
            AND a.action = 64
            AND a.createdon >= dateadd(month, -6, GETDATE())
         systemuserroles AS systemuserroles
         ON systemuserroles.systemuserid = s.systemuserid
         role AS role
         ON role.roleid = systemuserroles.roleid
            AND role.name LIKE ‘GMR SEC%’
GROUP BY a.actionname, a.objectid, s.fullname, s.domainname, s.internalemailaddress
ORDER BY lastloginutc DESC;

That’s it for today

I hope this helps.
Malla Reddy(@UK365GUY)