Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

Export Guides Operator and Guides Author members

(1) ShareShare
ReportReport
Posted on by 7

Need help exporting all of the accounts with the Guides Operator and Guides Author roles.  We have several Guides environments and need to collect this information for all of the environments.  Running a manual advanced query for each environment takes to long due to the number of environments we have.

  • Suggested answer
    Oren Shir Profile Picture
    Oren Shir on at
    RE: Export Guides Operator and Guides Author members

    If you look at the PowerShell in the Guide content migration tool (Migrate Dynamics 365 Guides content from one Microsoft Dataverse instance to another using the Content Migration Tool (Public Preview) - Dynamics 365 Mixed Reality | Microsoft Docs) you can find code snippets that can help you construct the script you need.

    Because you want to connect to many instances, I suggest you follow the instructions in Use PowerShell cmdlets for XRM tooling to connect to Microsoft Dataverse (Dataverse) - Power Apps | Microsoft Docs
    $Cred = Get-Credential
    $CRMConn = Get-CrmConnection -Credential $Cred -DeploymentRegion <Deployment region name> –OnlineType Office365 –OrganizationName <OrgName>
     
    You can also use connection string, just be careful about the where you put the password so it doesn't leak. You can also create an application user and associate it with a certificate if you don't want to sign in or have the password stored on a machine. Try to avoid using the options that just put the password in the connection string. Simplest way to start is
    $CRMConn = Get-CrmConnection -InteractiveMode
    The rest uses standard SDK queries. It is a little more complicated because roles to users is a N:N relationship
    $condition = new-object Microsoft.Xrm.Sdk.Query.ConditionExpression
    $condition.AttributeName = "name"
    $condition.Operator = "Equal"
    $condition.Values.Add("Dynamics 365 Guides Restricted Author")
    $filter = new-object Microsoft.Xrm.Sdk.Query.FilterExpression
    $filter.Conditions.Add($condition)
    $roleLink = new-object Microsoft.Xrm.Sdk.Query.LinkEntity
    $roleLink.LinkFromEntityName = "systemuserroles"
    $roleLink.LinkFromAttributeName = "roleid"
    $roleLink.LinkToEntityName = "role"
    $roleLink.LinkToAttributeName = "roleid"
    $roleLink.LinkCriteria.AddFilter($filter)

    $systemUserLink = new-object Microsoft.Xrm.Sdk.Query.LinkEntity
    $systemUserLink.LinkFromEntityName = "systemuser"
    $systemUserLink.LinkFromAttributeName = "systemuserid"
    $systemUserLink.LinkToEntityName = "systemuserroles"
    $systemUserLink.LinkToAttributeName = "systemuserid"

    $systemUserLink.LinkEntities.Add($roleLink)

    $linkQuery = new-object Microsoft.Xrm.Sdk.Query.QueryExpression $true
    $linkQuery.EntityName = "systemuser"
    $linkQuery.ColumnSet = new-object Microsoft.Xrm.Sdk.Query.ColumnSet($true)
    $linkQuery.LinkEntities.Add($systemUserLink);

    $request = new-object Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest
    $request.Query = $linkQuery
    $res = $CRMConn.Execute($request)

    The users are in $res.EntityCollection.Entities . You should loop over this collection and save it in the format you want. This link has examples Export-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs
  • Dan Coan Profile Picture
    Dan Coan 7 on at
    RE: Export Guides Operator and Guides Author members

    Yes, user accounts.

    PowerShell usually works easiest.

    Simple CSV file is sufficient.

    Yes, the default roles are the ones I looking for.

  • Oren Shir Profile Picture
    Oren Shir on at
    RE: Export Guides Operator and Guides Author members

    When you wrote accounts, did you mean users?

    Which tool do you want to use to get the information? You can use PowerShell, Power Automate, or write code, and more.

    Where do you want to export to? A file like excel/xml/json/csv, or some other system like a SharePoint table?

    I assume the roles are the default ones that come with the product.

     

    The information is all in CDS, this is an example for how to use the API Sample: Associate a Security Role to a User (Developer Guide for Dynamics 365 Customer Engagement) | Microsoft Docs . You need to decide on your favorite way to interact with the systemuserroles_association collection value navigation property of the role EntityType (Microsoft.Dynamics.CRM) | Microsoft Docs .

    For example, if you want to use PowerShell you can get started at Microsoft Dynamics CRM PowerShell Reference | Microsoft Docs .

    There are many links about using Power Automate to query CDS.

    After you add more details we can help you find the solution you need.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,703 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans