title: Replacing dynamic variables using REGEX content as variable in Azure CD Pipeline Powershell Task
body: <p>I'm writing custom Powershell Azure CD Pipeline task(for VM) where my web.config should be replaced with pipeline variables. I have sample config file as with <strong>WebService</strong> and <strong>AuditService</strong> defined in my Azure CD pipeline variables.</p>
  
  <pre><code>&lt;client&gt;
        &lt;endpoint address="__WebService__" binding="basicHttpBinding" bindingConfiguration="ServiceSoap" contract="WebServiceClient.ServiceSoap" name="NLSService" /&gt;
        &lt;endpoint address="__AuditService__" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Audit" contract="AuditApiService.Audit" name="AuditService" /&gt;
      &lt;/client&gt;
  </code></pre>
  
  <p>I have powershell script as </p>
  
  <pre><code>$zipfileName = "$(System.DefaultWorkingDirectory)\_WebService-CI\drop\Service.zip"
  $fileToEdit = "web.config"
  $reg = [regex] '__(.*?)__'
  
  
  [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem");
  # Open zip and find the particular file (assumes only one inside the Zip file)
  $zip =  [System.IO.Compression.ZipFile]::Open($zipfileName,"Update")
  $configFile = $zip.Entries.Where({$_.name -like $fileToEdit})
  
  # Read the contents of the file
  $desiredFile = [System.IO.StreamReader]($configFile).Open()
  $text = $desiredFile.ReadToEnd()
  $desiredFile.Close()
  $desiredFile.Dispose()
  
  
  $text = $text -replace $reg, $(${1}) -join "`r`n"
      #update file with new content
  $desiredFile = [System.IO.StreamWriter]($configFile).Open()
  $desiredFile.BaseStream.SetLength(0)
  
  # Insert the $text to the file and close
  $desiredFile.Write($text)
  $desiredFile.Flush()
  $desiredFile.Close()
  
  # Write the changes and close the zip file
  $zip.Dispose()
  </code></pre>
  
  <p>So how do I can replace dynamically Regex content within "__" and treat that content as a variable which should look into pipeline variables and replace it in line :</p>
  
  <p><code>$text = $text -replace $reg, $(${1}) -join "</code>r<code>n"</code></p>