Create a Power Platform RESX Web Resource via PowerShell
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.
Below is the full code snippet. Below variables must be set for each personal situation. I have obfuscated secure and personnel information.
$filename - the name of the file on your computer (locally) containing the XML language translations.
$path - the location of the RESX file on your computer (locally).
$username - user name of the Power Platform where the RESX web resource will be created
$password - password of the Power Platform where the RESX web resource will be created
$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.
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.
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.
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
content is set to the base 64 binary contents of the local file.
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.
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.
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.