top of page

Create a Power Platform RESX Web Resource via PowerShell

Updated: Jun 3, 2023

Overview

Below is a quick code snippet that I am using to add RESX Web Resources to the Power Platform.


I am using the RESX files to store "magic strings" so that text in power automate, custom workflow activities, JS web resources and plugins can be translated (localized) to other languages.


What are RESX Files

RESX Web Resources are files that store key-value pairs of strings. RESX files are used to aid localisation in Power Platform applications.


The Microsoft website describes the purpose of RESX Web Resources as; "Use these web resources to manage localized strings in any user interface you define or with error messages you will display.". - String (RESX) web resources (model-driven apps) - Power Apps | Microsoft Learn.


Important Variables

Below is the full code snippet. Below variables must be set for each personal situation. I have obfuscated secure and personnel information.

  1. $filename - the name of the file on your computer (locally) containing the XML language translations.

  2. $path - the location of the RESX file on your computer (locally).

  3. $username - user name of the Power Platform where the RESX web resource will be created

  4. $password - password of the Power Platform where the RESX web resource will be created

  5. $organizationName - the name of the Power Platform organization where the RESX web resource will be created. It can be found on the classic settings page under settings->customizations->developer resources.

The Script

Walking Through The Script

The first few lines get contents from the local RESX file and save it as a string in variable $fileContentAsString.

Next, convert the RESX file contents from string to base 64 binary. This is required. Otherwise, an error will occur when creating the RESX file.

A Power Platform connection must be created before creating a RESX file. The below code creates the connection using a user's username and password. The code can be modified to display a login dialog, or to use an application user's client secret.

A variable, $fields, contains values for all the mandatory fields for a RESX web resource record.

  1. name is set to cc_newfile1; this was lazy coding by me and will need to be changed to what your name should be. Note generally, the RESX web resource name will contain the language code.

  2. webresourcetype is set to an option set value of 12. 12 is the value for a RESX String web resource. A full list of resource types and their option set values can be found at Web Resources (model-driven apps) - Power Apps | Microsoft Learn

  3. content is set to the base 64 binary contents of the local file.

  4. languagecode is the language that the translations RESX will be used for. a full list of LCIDs/language codes can be found at Microsoft Dataverse language collations - Power Platform | Microsoft Learn

Finally, we create the web resource record using the New-CrmRecord cmdlet.


Use Cases

I use this script to quickly create RESX web resources for a project that I am on as manually creating all the required RESX files manually would be time-consuming. Additionally, with some customisation, this could be used in an ALM, CI/CD pipeline to upsert RESX files to a target environment.


Moving Forward

I will be adding a PowerShell snippet to upsert web resources to a Git Repo in the near future. D365Freelancing/Powershell: Dataverse and Project related Powershell scripts (github.com)


Try this if you have errors running the script.

Errors running the script might be caused by not having Microsoft.Xrm.Tooling.CrmConnector.PowerShell or Microsoft.Xrm.Data.Powershell cmdlets installed.


86 views0 comments

Recent Posts

See All

10 Tips to Speed Up your Data Migration

There are a number of tricks that can help improve the speed of data migrations. I have bullet pointed them below and included links and references at the bottom of the page. Turn off all workflows (i

bottom of page