使用Powershell解析xml时出现问题

时间:2019-01-04 16:56:40

标签: xml powershell system.web

看下面的xml示例,当您将其加载到powershell中时,不允许您在$ myXML.configuration.system.web之外的源进行点缀,因此不允许访问该元素的内部。这是因为元素名称中的句点吗?如果是这样,我无法更改,那么解决方法是什么?

我可以键入(例如)类型$ myXML.configuration.'system.web',但是除非有意料之外,否则我将无法继续深入标签/元素,除非我做错了事(因此, )。我无法获取编译内部的程序集,甚至无法获取system.web内部的编译

我的最终目标是能够检查是否存在任何元素/值,如果不存在则将其添加,或者如果设置不正确则对其进行更改。

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

下面是xml内容

<?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>

0 个答案:

没有答案