Update Azure Service Configuration File using Powershell


I'm trying to write a powershell script that updats each of the DiagnosticsConnectionString and DataConnectionString values below, but I can't seem to find each individual Role node using


doing echo $serviceconfig.ServiceConfiguration.Role lists out both Role nodes for me so I know it is working up to that point, but after that I am not having much success.

where $serviceConfig contains the below XML:

<?xml version="1.0"?>
<ServiceConfiguration serviceName="MyService"  xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
  <Role name="MyService_WorkerRole">
    <Instances count="1" />
      <Setting name="DiagnosticsConnectionString" value="really long string" />
      <Setting name="DataConnectionString" value="really long string 2" />
  <Role name="MyService_WebRole">
    <Instances count="1" />
      <Setting name="DiagnosticsConnectionString" value="really long string 3" />
      <Setting name="DataConnectionString" value="really long string 4" />

I would skip the XPath and just filter with PowerShell.

$serviceConfig.ServiceConfiguration.Role |
    ? { $_.name -eq 'MyService_WorkerRole' } |
    % { $_.ConfigurationSettings.Setting } |
    ? { $_.name -like 'Diag*' } |
    % { $_.value = 'sup' }

At this point if we do something like this...


We'll get this...

<ConfigurationSettings xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
  <Setting name="DiagnosticsConnectionString" value="sup" />
  <Setting name="DataConnectionString" value="really long string 2" />
By : dahlbyk

This video can help you solving your question :)
By: admin