lipkau / PsIni

Work with INI files in PowerShell using hashtables
http://lipkau.github.io/PsIni
MIT License
152 stars 52 forks source link

Wrong order in Out-IniFile #72

Open mmusolesi opened 2 years ago

mmusolesi commented 2 years ago

Out-IniFile retunrs wrong ordered category.

Example: $Category1 = @{"Key1"="Value1";"Key2"="Value2"} $Category2 = @{"Key1"="Value1";"Key2"="Value2"} $NewINIContent = @{"Category1"=$Category1;"Category2"=$Category2} Out-IniFile -InputObject $NewINIContent -FilePath "C:\temp\settings.ini"

Output content: [Category2] Key1=Value1 Key2=Value2 [Category1] Key1=Value1 Key2=Value2

exchange12rocks commented 1 year ago

That's how PowerShell hashtables are designed. Just use ordered hashtables: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7.3#creating-ordered-dictionaries

$NewINIContent = [ordered]@{"Category1"=$Category1;"Category2"=$Category2}
HighPriest commented 4 weeks ago

This issue could be closed. The Out-IniFile and Get-IniContent work with ordered hashables without issues.