I am new to Powershell scripts that parses XML and I just ran into a situation where I needed to make sure a line of XML got executed strictly before another.
To get there, I first searched on how I would be reading the XML file and this is what I got:
[XML]$Web = Get-Content *path_to_XML_file*
Using the dot notation, I travelled to the node that contained the line that needed to be validated (I still dont know how I will manage to find the line number to figure out if it came before or after the other).
The node I needed to iterate through was located at:
$Web.Configuration.location.'system.WebServer'.modules
Heres a console output when I entered that last line:
add
---
{HttpCacheModule, DynamicCompressionModule, IsapiFilterModule, ProtocolSupportModule...}
This node contained multiple instances of other nodes named 'add' but was of type System.Array.
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
Also, heres a copy of the modules nodes that are in the XML:
<modules>
<add name="HttpCacheModule" lockItem="true" />
<add name="DynamicCompressionModule" lockItem="true" /> <--HERE
<add name="IsapiFilterModule" lockItem="true" />
<add name="ProtocolSupportModule" lockItem="true" />
<add name="StaticFileModule" lockItem="true" />
<add name="AnonymousAuthenticationModule" lockItem="true" />
<add name="DefaultDocumentModule" lockItem="true" />
<add name="CustomErrorModule" lockItem="true" />
<add name="HttpRedirectionModule" lockItem="true" />
<add name="RequestFilteringModule" lockItem="true" />
<add name="IsapiModule" lockItem="true" />
<add name="ConfigurationValidationModule" lockItem="true" />
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" preCondition="managedHandler" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="managedHandler" />
<add name="WindowsAuthenticationModule" lockItem="true" />
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" preCondition="managedHandler" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="managedHandler" />
<add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition="managedHandler" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" preCondition="managedHandler" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" preCondition="managedHandler" />
<add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" preCondition="managedHandler" />
<add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" preCondition="managedHandler" />
<add name="Profile" type="System.Web.Profile.ProfileModule" preCondition="managedHandler" />
<add name="UrlMappingsModule" type="System.Web.UrlMappingsModule" preCondition="managedHandler" />
<add name="BasicAuthenticationModule" lockItem="true" />
<add name="HttpLoggingModule" lockItem="true" />
<add name="StaticCompressionModule" lockItem="true" />
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler,runtimeVersionv2.0" />
<add name="ServiceModel-4.0" type="System.ServiceModel.Activation.ServiceHttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="managedHandler,runtimeVersionv4.0" />
<add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" />
<add name="ClientLoggingHandler" />
<add name="AdvancedLoggingModule" />
<add name="AppWarmupModule" />
<add name="RewriteModule" /> <---- HERE
<add name="FailedRequestsTracingModule" lockItem="true" />
<add name="F5XFFHttpModule" />
</modules>
I need to make sure the line <add name="DynamicCompressionModule" lockItem="true" />
absolutely gets executed before <add name="RewriteModule" />
and I don't know how to iterate through this System.Array to get there.
Could anyone help me with that, please?
Select-Xml
.