Skip to content

Instantly share code, notes, and snippets.

@sunnyc7
Created April 4, 2013 14:07
Show Gist options
  • Save sunnyc7/5310649 to your computer and use it in GitHub Desktop.
Save sunnyc7/5310649 to your computer and use it in GitHub Desktop.
Convert Web.Config to a hashtable. Use Keys to get the values.
<#
web.config.xml
<configuration>
<applicationSettings>
<add key="machineName" value="Prod" />
<add key="anotherMachineName" value="Test" />
<add key="EnvTypeDefault" value="Dev" />
<add key="RootURLProd" value="http://domain.com/app/" />
<add key="RootURLTest" value="http://test.domain.com/app/" />
<add key="RootURLDev" value="http://localhost/app/" />
<add key="HumanReadableEnvTypeProd" value="" />
<add key="HumanReadableEnvTypeTest" value="Test Mode" />
<add key="HumanReadableEnvTypeDev" value="Development Mode" />
</applicationSettings>
</configuration>
#>
[xml]$webconf = Get-Content 'web.config.xml'
$x = $webconf.configuration.applicationSettings.add
$hash = @{}
foreach ($y in $x) {
$hash.Add($y.key,$y.Value)
}
$hash.machineName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment