0

Looking at the xml example below, when you load this into powershell it does not allow you to dot source beyond $myXML.configuration.system.web and therefore not allow access to the innards of that element. Is this because of the period in the element name? I can't alter that if that's the case, so what would be the work around?

I'm able to type (for example) type $myXML.configuration.'system.web' but I cannot continue further down the tags/elements, unless that's expected and I'm doing something wrong afterwards (hence the question). I cannot source to assemblies inside of compilation or even compilation inside of system.web

My end goal is to be able to check for existence of any element/value and then add it if it doesn't exist or change it if it is set incorrectly.

$path = "c:\temp\web2.config";
[xml]$myXML = Get-Content $path;

Below is the xml contents

<?xml version="1.0" encoding="UTF-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="HttpProxy.ProtocolType" value="Eas" />
    <add key="OAuthHttpModule.Profiles" value="V1AppActAs" />
    <add key="OAuthHttpModule.V1AppScopes" value="EAS.AccessAsUser.All" />
  </appSettings>
  <system.webServer>
    <modules>
      <remove name="ServiceModel" />
      <remove name="ServiceModel-4.0" />
      <add name="HostHeaderValidationModule" type="Microsoft.Exchange.HttpUtilities.HostHeaderValidationModule, Microsoft.Exchange.HttpUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=xxxxx" />
      <add name="CasHealthModule" type="Microsoft.Exchange.Common.ExWebHealthModule,Microsoft.Exchange.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=xxxxx" />
      <add name="HttpProxy" type="Microsoft.Exchange.HttpProxy.ProxyModule,Microsoft.Exchange.FrontEndHttpProxy,Version=15.0.0.0,Culture=neutral,PublicKeyToken=xxxxx" preCondition="" />
      <add name="OAuthAuthModule" type="Microsoft.Exchange.Security.OAuth.OAuthHttpModule" />
    </modules>
    <httpErrors existingResponse="PassThrough" />
    <httpRedirect enabled="false" />
    <httpProtocol>
      <customHeaders>
        <add name="X-FEServer" value="xxxxx" />
      </customHeaders>
      <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="250000" />
        </requestFiltering>
    </security>
    </httpProtocol>
  </system.webServer>
  <system.web>
    <machineKey validationKey="AutoGenerate,IsolateApps" />
    <compilation defaultLanguage="c#" debug="false">
      <assemblies>
        <add assembly="Microsoft.Exchange.Clients.Strings, Version=15.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.Data.Directory, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.Clients.Common, Version=15.0.0.0,Culture=neutral, publicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.Clients.Security, Version=15.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.Security, Version=15.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.FrontEndHttpProxy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="Microsoft.Exchange.HttpProxy.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="10240" />
  </system.web>
</configuration>
Bbb
  • 517
  • 6
  • 27
  • since the properties have a dot in them, have you tried to use `$myXML.configuration.'system.web'.machineKey`? – Lee_Dailey Jan 04 '19 at 17:10
  • when i load your XML, i can use the code i posted to get deep into the object. this ... `$myXML.configuration.'system.web'.compilation.assemblies.add[0].assembly` ... gives me `Microsoft.Exchange.Clients.Strings, Version=15.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35`. – Lee_Dailey Jan 04 '19 at 18:16
  • To answer my own question, you cannot get dot sourcing out of it, you have to manually type it out and it will return a value using a format like Lee Dailey has, it will not dot source with intellisense. – Bbb Jan 04 '19 at 19:24
  • You mean dot-access. Dot-sourcing is something completely different. – Ansgar Wiechers Jan 04 '19 at 20:51

0 Answers0