Using PowerShell to Read a NAVISION File .CONFIG
source link: https://www.codesd.com/item/using-powershell-to-read-a-navision-file-config.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using PowerShell to Read a NAVISION File .CONFIG
I have an config file from a NAVISION instance.
The file format is like this:
<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
<add key="NetType" value="Default"></add>
<add key="DatabaseServer" value="SQLSERVER"></add>
<add key="DatabaseInstance" value="MSSQL"></add>
......
</appSettings>
I currently use this code:
[xml]$configfile = Get-Content "CustomSettings.config"
$appsettings = $configfile.appSettings.add.GetEnumerator()
Echo $appsettings
The end result that I get in Powershell is this:
key value
--- -----
NetType Default
DatabaseServer SQLSERVER
DatabaseInstance MSSQL
... .....
However if I try to get for instance the DatabaseServer with $appsettings.'DatabaseServer' (or $appsettings.DatabaseServer) it will return nothing.
This works;
ForEach ($keypair in $appsettings) {
echo $($keypair.Key + " - " + $keypair.Value);
}
But since I only need to have 5 values, I don't want to create an ForEach loop with 5 IFs.. there must be a better/faster way. Thanks in advance!
Maybe
PS>($configfile.appSettings.add | ?{$_.key -eq "databaseserver"}).value
SQLSERVER
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK