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
$serviceconfig.ServiceConfiguration.SelectSingleNode("Role[@name='MyService_WorkerRole']")
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" />
<ConfigurationSettings>
<Setting name="DiagnosticsConnectionString" value="really long string" />
<Setti开发者_开发技巧ng name="DataConnectionString" value="really long string 2" />
</ConfigurationSettings>
</Role>
<Role name="MyService_WebRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="DiagnosticsConnectionString" value="really long string 3" />
<Setting name="DataConnectionString" value="really long string 4" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
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...
$serviceConfig.ServiceConfiguration.Role[1].ConfigurationSettings.OuterXml
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" />
</ConfigurationSettings>
精彩评论