<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" safemode="true"/>
<requiredRuntime version="v2.0.50727" safemode="true"/>
</startup>
<appSettings>
<add key="Editions" value="Standard Edition,Desktop Edition,Desktop Engine,Evaluation Edition,Enterprise Edition,Developer Edition,Personal Edition,Enterprise Edition (64-bit),Developer Edition (64-bit),Enterprise Evaluation Edition,Small Business Server Edition" />
<add key="Categories" value="Backup and Recovery,Configuration Options,Database Design,Database Administration,Deprecation,Full-Text,General Administration,Generic,T-SQL,SQL Server 2005 Readiness" />
<add key="DataTypes" value="string,int,double" />
<add key="Database" value="" />
<add key="SQLServer" value="" />
<add key="WindowsAuthentication" value="" />
<add key="MaxScanDetailRows" value="500" />
<!– Logging level. 0 – Off, 1 – Error, 2 – Warning, 3 – Info, >=4 – Verbose –>
<add key="LoggingLevel" value="2" />
</appSettings>
</configuration>
$config = [xml](get-content $path)
foreach ($addNode in $config.configuration.appsettings.add) {
if ($addNode.Value.Contains(‘,’)) {
# Array case
$value = $addNode.Value.Split(‘,’)
$value[$i] = $value[$i].Trim()
}
}
else {
# Scalar case
$value = $addNode.Value
}
$global:appSettings[$addNode.Key] = $value
}
500
$appSettings["datatypes"]
string
int
double
$appSettings["datatypes"][0]
string
Nice. +1
Pingback: Technical: Microsoft – SharePoint – List – Programmatically list contents ( Using Web Services) | Learning in the Open
Hello,
As I try to implement a configuration file in .xml for my batch scripts, I encounter the
limitation below when settings are built on other settings like JavaHome, which would uses ProgDir in the example below. I wonder if you have any suggestion to overcome it?
$appSettings[“ProgDir”]
D:\Programs
$appSettings[“JavaHome”]
$appSettings[“ProgDir”]\Jre\jre7 << I would need it to be resolved as D:\Programs\Jre\jre7" instead
Thanks in advance for your help,
calagan
Try “$($appSettings[‘ProgDir’])\Jre\jre7”
Thank you, appreciated!
So how can I modify and save the settings into this xml? Is there a solution for that?
Sure, just use the Save() method on the $config variable e.g. $config.Save(“$pwd\foo.xml”).