I am trying to build a PowerShell script such that I give it an input file and regex, it replaces the matching content with the environment variable.
For example, if the input file contains the following:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/Services" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="IntegrationManager_PartitionCount" Value="1" />
<Parameter Name="IntegrationManager_MinReplicaSetSize" Value="2" />
<Parameter Name="IntegrationManager_TargetReplicaSetSize" Value="#{INT_MGR_IC}" />
<Parameter Name="EventManager_InstanceCount" Value="#{EVT_MGR_IC}" />
<Parameter Name="Entities_InstanceCount" Value="#{ENT_IC}" />
<Parameter Name="Profile_InstanceCount" Value="#{PRF_IC}" />
<Parameter Name="Identity_InstanceCount" Value="#{IDNT_IC}" />
</Parameters>
</Application>
I would like to build a script that replaces #{INT_MGR_IC}
with the value of the INT_MGR_IC
environment variable and so on.
Specifically, I am interested to know how to:
- Extract and loop over keys from the file such as:
#{INT_MGR_IC}
,#{EVT_MGR_IC}
, etc. - Once I have the key, how do I replace it with an associated environment variable. For example,
#{INT_MGR_IC}
withINT_MGR_IC
env. variable.
Update
This is the RegEx I am planning to use: /#{(.+)}/g