Skip to content

Instantly share code, notes, and snippets.

@rasmuseeg
Last active August 9, 2021 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasmuseeg/f69fa31837382b5ea2272fcb9213652c to your computer and use it in GitHub Desktop.
Save rasmuseeg/f69fa31837382b5ea2272fcb9213652c to your computer and use it in GitHub Desktop.
Read ini file contents using powershell
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