txchen
4/1/2013 - 8:55 PM

A modified version from http://blogs.technet.com/b/heyscriptingguy/archive/2011/08/20/use-powershell-to-work-with-any-ini-file.aspx , improv

function ParseIni ($filePath)
{
    $ini = @{}
    switch -regex -file $FilePath 
    { 
        "^\[(.+)\]$" # Section 
        { 
            $section = $matches[1] 
            $ini[$section] = @{}
        }
        "^([^;].*[^\s])\s*=\s*([^\s].*[^\s])$" # Key 
        {
            if (!($section)) 
            { 
                $section = "No-Section" 
                $ini[$section] = @{} 
            } 
            $name,$value = $matches[1..2] 
            $ini[$section][$name] = $value 
        } 
    }
    Return $ini 
}