Last active
August 9, 2021 12:46
-
-
Save rasmuseeg/f69fa31837382b5ea2272fcb9213652c to your computer and use it in GitHub Desktop.
Read ini file contents using powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertFrom-Ini ($filePath) | |
{ | |
$ini = @{} | |
$section = $ini | |
switch -regex -file $FilePath | |
{ | |
“^\[(.+)\]” # Section | |
{ | |
$section = $matches[1] | |
$ini.Add($section,@{}) | |
$CommentCount = 0 | |
} | |
“^(;.*)$” # Comment | |
{ | |
$value = $matches[1] | |
$CommentCount = $CommentCount + 1 | |
$name = “Comment” + $CommentCount | |
$section.Add($name,$value) | |
} | |
“(.+?)\s*=(.*)” # Key | |
{ | |
$name,$value = $matches[1..2] | |
$section.Add($name,$value) | |
} | |
} | |
return $ini | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment