Skip to content

Instantly share code, notes, and snippets.

@krokofant
Created September 24, 2024 13:48
Show Gist options
  • Save krokofant/d3a1f5f01f09a8bb2d835ffd8e8708a3 to your computer and use it in GitHub Desktop.
Save krokofant/d3a1f5f01f09a8bb2d835ffd8e8708a3 to your computer and use it in GitHub Desktop.
function Get-IniContent ($filePath) {
$ini = @{}
switch -regex -file $FilePath {
"^\[(.+)\]" { # Section
$section = $matches[1]
$ini[$section] = @{}
$CommentCount = 0
continue
}
"^(;.*)$" { # Comment
$value = $matches[1]
if ($null -eq $section) { continue } # Ignore global comment
$CommentCount = $CommentCount + 1
$name = "Comment" + $CommentCount
$ini[$section][$name] = $value
continue
}
"(.+?)\s*=(.*)" { # Key
$name, $value = $matches[1..2]
$ini[$section][$name] = $value
continue
}
}
return $ini
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment