Use AI to move selected security objects between environments
When configuring security in Dynamics 365 F&O, you can export and import the changes to move them between different environments and publish them eventually into the production environment. For moving the objects, the supported options out of the box is about moving all changes in one go. However, there are scenarios where you would like to have an easy process to move one role, or a selection of security roles. In this post, I will show you how you can use AI to determine what changes need to be moved to another environment.
Supported options
In the past, I wrote blogs about moving security by exporting the security configuration into an XML file and an option to use data management with data entities.
- How to: Move security configurations across Dynamics 365 environments
- Move all user and security settings with data entities – Dynamicspedia
When moving the security to a production environment, it is recommended to export the security as tested in an acceptance environment. Using the data entities option, you can select which elements to export, but this has limitations, as you can only select based on the object Identifier or Record IDs. It will be too hard to find this information for the duties and privileges that are linked to a specific security role. Once you have the list, it will be cumbersome to put it in a filter.
It is possible to edit the export files before importing them, but there is a risk that a user will not get the security as it was tested. When moving customizations, you also move the full package instead of cherry-picking functionality again.
There are several valid requirements for moving only a subset between environments. Some of them are:
- A standard object was touched by accident and is now part of the export.
- Two streams are responsible for security object changes; e.g., during rollouts, there might be a support team and a roll-out team making changes in security starting from different environments.
- Preventing security object history growth for objects that were not modified but are included in the file.
There are some ISV solutions available that will give you the option to export a subset of the changed configuration. Now, let’s look at another option where you can use AI to update the exported details with only the security changes you need.
Edit exported file using AI
A few months ago, I was evaluating the option to use Microsoft 365 Copilot or Claude for editing the exported security object changes before importing them into another environment. Since that time, it helped at various clients to move only the relevant changes. Before sharing the details, first, a disclaimer.
AI-generated content may contain errors. Editing the details of the exported security configurations should be validated and tested thoroughly.
Large Language Models (LLMs) are great at understanding structured file data. When you export the security database configurations from the Security Configuration page, the details are exported in an XML file.

The details do have a specific structure. When you open the file with an editor tool, like Microsoft XML Notepad, you can check the details of the file.

The file has a main node for the three types of security objects. Each node has child leaves with changes to standard objects, disabled objects, and newly configured objects. When you continue expanding the objects, like an AxSecurityRole, you can see the duties and privileges. and table permissions added to a role.
In the past, I cleaned the file manually by removing elements that should not be imported in another environment and sometimes even corrected object labels when it contained a typo. This is also explained in one of the blogs I shared above.
It was always a cumbersome process, for sure, when a file contains a lot of newly added security roles, duties, and privileges. Then I started using Copilot and Claude to perform the task on my behalf. After a few attempts, I got a reliable result, even with a report added about what changes were made to the file. When you look at the screenshots above, you can see that there are some new “customer roles”, and the export file contains standard elements that should not be moved to the next environment.
You can have AI clean the file for you. In M365 Copilot Chat and Claude, I’m now using the following prompt:
I have attached an XML file containing Dynamics 365 AI ERP security configurations that need cleanup. The file contains three sections. One for security roles (AxSecurityRole), one for duties (AxSecurityDuty), and one for privileges (AxSecurityPrivilege). Each section has sub-sections for a CustomizedObjectList, DisabledObjectSet, and NewObjectList. All siblings from the DisabledObjectSet need to be removed. From the security roles, duties, and privileges, remove all CustomizedObjectList elements, and from the NewObjectList, remove all nodes where the Label does not start with the prefix "(DynPed)". Note that the prefix includes the brackets. Next, security roles do have a reference to Duties and/or Privileges. Security duties have a reference to privileges. Remove all duties that are not referenced by any security role. From the privileges, remove all that are not referenced by any duty or security role. The file should start with a first node named SecurityCustomizationData, and this should remain as the first node. A first root node with "<xml>" is not allowed to be part of the file. Also, create an Excel workbook with a sheet per securable object type for all the elements, with their status, whether it is kept in the file or removed. Each sheet should have the columns Name, Label, and Status. Also create a sheet with a summary of how many objects were identified, kept, and deleted. Please execute the task and return a cleaned SecurityCustomizationData file and the Excel log.

With this prompt, the file will be analyzed, and AI will create and execute Python scripts that will either remove or rebuild the XML file with only the content that should be kept. There was a small difference in execution when using M365 Copilot or Claude. One of my clients has a huge file with customizations. It contained over 1000 roles with their details and was just over 350 MB in size. Copilot sometimes stopped executing and only provided Python scripts to be run by me. Claude did do the job in all occasions. Without specific prompting, M365 Copilot added a new root node, which caused issues when importing the file. That is the reason why it was added to the prompt.
For writing this blog, I used Copilot. When it was finished, it returned a cleaned XML file and, as requested, an Excel file to help validate the output of the generated security customizations file.

Before using the newly generated file to be imported, ensure you check the details first. The Excel file gives you insights, but you will also need to validate the file in a non-production environment first.

The Excel file has, next to a summary page, details about which roles, duties, and privileges were kept or deleted. From the deleted duties, some contained the prefix with (DynPed), but got removed at it wasn’t referenced in any role.
Move specific selected elements
The example above was an instruction where all elements with a specific prefix were kept, and non-referenced objects were removed. Suppose you want to move only specific roles and their linked duties and privileges. In that case, you can again use AI, but with a slightly different prompt. The roles were configured in a development environment from where I only want to move relevant roles to a sandbox for user acceptance testing. Suppose I want to keep the following security roles:
- (DynPed) Accountant light
- (DynPed) Accounting supervisor light
- (DynPed) Customer master data
- (DynPed) Project manager
- (DynPed) Purchase requisitions
- (DynPed) Read only
- (DynPed) Senior accountant
- (DynPed) Vendor bank account
- (DynPed) Warehouse mobile device
In that case, we can use the next prompt together with providing the security database configuration file:
I have attached an XML file containing Dynamics 365 AI ERP security configurations that need cleanup. The file contains three sections. One for security roles (AxSecurityRole), one for duties (AxSecurityDuty), and one for privileges (AxSecurityPrivilege). Each section has sub-sections for a CustomizedObjectList, DisabledObjectSet, and NewObjectList. All siblings from the DisabledObjectSet need to be removed. From the security roles, remove all roles except for those meeting this list: (DynPed) Accountant light (DynPed) Accounting supervisor light (DynPed) Customer master data (DynPed) Project manager (DynPed) Purchase requisitions (DynPed) Read only (DynPed) Senior accountant (DynPed) Vendor bank account (DynPed) Warehouse mobile device Next, security roles do have a reference to Duties and/or Privileges. Security duties have a reference to privileges. Remove all duties that are not referenced by any security role. From the privileges, remove all that are not referenced by any duty or security role. The file should start with a first node named SecurityCustomizationData, and this should remain as the first node. A first root node with "<xml>" is not allowed to be part of the file. Also, create an Excel workbook with a sheet per securable object type for all the elements, with their status, whether it is kept in the file or removed. Each sheet should have the columns Name, Label, and Status. Also create a sheet with a summary of how many objects were identified, kept, and deleted. Please execute the task and return a cleaned SecurityCustomizationData file and the Excel log.
After providing the prompt and getting the files returned, you can evaluate the outcomes. The Excel file showed more objects deleted than the first example. Next, for roles not mentioned, it removed the duties and privileges not referenced by the roles that were kept. You can then import the file into Dynamics 365 F&O.

There is more…
In the above-mentioned prompts, there are instructions to remove customized objects and deleted objects. If you have adjusted standard objects or disabled standard roles, you will need to remove these instructions from the prompt.
You can also create a skill for the Dynamics 365 security customizations cleanup. All important file structure details and the requirement for the Excel validation sheet will then be part of it for the guardrails. In case of repeatable queries, after creating the skill, the prompt can be shorter and simplified. I created a skill in Cowork myself, and by only prompting the next prompt, it gave the correct result and the Excel file for validation.
Please clean up this Dynamics 365 F&O security file. Only the read-only role and related objects should be retained.
I do hope you liked this post and will add value for you in your daily work as a professional. If you have related questions or feedback, don’t hesitate to use the Comment feature below.
That’s all for now. Till next time!



Arek Socha from Pixabay
by Geralt on Pixabay
Image by Gerd Altmann from Pixabay

Leave a Reply
Want to join the discussion?Feel free to contribute!