I'm attempting to remove the defining of variables from a script and read them in from an XML configuration file similar to the below:
XML File
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<process>FALSE</process>
<xmlDir>\\serv1\dev</xmlDir>
<scanDir>\\serv1\dev</scanDir>
<processedDir>\\serv1\dev\done</processedDir>
<errorDir>\\serv1\dev\err</errorDir>
<log>\\serv1\dev\log\dev-Log##DATE##.log</log>
<retryDelay>5</retryDelay>
<retryLimit>3</retryLimit>
</settings>
Then parse the XML in the script with the below:
[xml]$configFile = Get-Content $PSScriptRoot\$confFile
$settings = $configFile.settings.ChildNodes
foreach ($setting in $settings) {
New-Variable -Name $setting.LocalName -Value ($setting.InnerText -replace '##DATE##',(get-date -f yyyy-MM-dd)) -Force
}
This works great but the problem is that they are all read as a string but some I require as an integer. To get around this issue I'm having to change them to integer after the variables have been created as below:
$retryDelay = ([int]$retryDelay)
$retryLimit = ([int]$retryLimit)
Although this works, I'd like to have other variables in the XML such as boolean $true / $false (and read in as a boolean) and would rather have the foreach be able to handle their types rather than additional lines in the script. Any clues appreciated.