I\'m parsing simple (no sections) INI file in PowerShell. Here code I\'ve came up with, is there any way to simplify it?
convertfrom-stringdata -StringData (
One possibility is to use a .NET ini library. Nini for example.
I've translated the Simple Example from the Nini docs into PowerShell below. You need to put nini.dll into the same directory as the script.
$scriptDir = Split-Path -parent $MyInvocation.MyCommand.Definition
Add-Type -path $scriptDir\nini.dll
$source = New-Object Nini.Config.IniConfigSource("e:\scratch\MyApp.ini")
$fileName = $source.Configs["Logging"].Get("File Name")
$columns = $source.Configs["Logging"].GetInt("MessageColumns")
$fileSize = $source.Configs["Logging"].GetLong("MaxFileSize")