lipkau / PsIni

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

Can't get all section names from big ini file #76

Closed Po-temkin closed 1 year ago

Po-temkin commented 1 year ago

I think that I found certain bug. I have quite big ini file and when I trying to get names of all Sections I see Keys names of fist Section instead of it.

PS C:\Windows\system32> (Get-IniContent -FilePath 'C:\Users\admin\Desktop\indexes.txt').Keys

Name                           Value
----                           -----
coldPath                       $SPLUNK_DB\$_index_name\colddb
coldToFrozenDir
enableDataIntegrityControl     0
enableTsidxReduction           0
frozenTimePeriodInSecs         2678400
homePath                       $SPLUNK_DB\$_index_name\db
maxTotalDataSizeMB             512000
thawedPath                     $SPLUNK_DB\$_index_name\thaweddb
timePeriodInSecBeforeTsidxR...
tsidxReductionCheckPeriodInSec
repFactor                      auto

indexes.txt

CanMonster commented 1 year ago

Hi Po-temkin,

I have had a quick look and I can see what the issue is. I can tell you that the issue is not relate to the size of the INI but rather there looks to be a "Keyword" conflict between the content of your Indexes.ini file and the Ordered Dictionary the Get-IniContent function creates.

The Get-IniContent function creates an Order Dictionary which has two properties, Keys and Values. The function uses the [Section Name] as the Key and the values are the key = value pairs beneath each.

Ordered Dictionary Key = "[Section]" Values = An array of the "Key = value" pairs beneath each section

Your Index.txt file contains a Section named [keys], i.e.

[keys] coldPath = $SPLUNK_DB\$_index_name\colddb coldToFrozenDir = enableDataIntegrityControl = 0 enableTsidxReduction = 0 frozenTimePeriodInSecs = 2678400 homePath = $SPLUNK_DB\$_index_name\db maxTotalDataSizeMB = 512000 thawedPath = $SPLUNK_DB\$_index_name\thaweddb timePeriodInSecBeforeTsidxReduction = tsidxReductionCheckPeriodInSec = repFactor = auto

The [keys] section is conflicting with the "Keys" property of the Ordered Dictionary.

So when you use:

(Get-IniContent -FilePath 'C:\Users\admin\Desktop\indexes.txt').Keys

You are literally getting the Key and Values pairs for the Key "[keys]" as apposed to the complete list of Keys in the Ordered Dictionary.

There is nothing to fix per say. If you rename the [keys] section to something else, e.g. [keyz] and then use:

(Get-IniContent -FilePath 'C:\Users\admin\Desktop\indexes.txt').Keys

You will get a complete listing of the keys.

Hope this helps.

CanMonster commented 1 year ago

Hi Po-temkin,

Some further research has shown that this is an known and open issue.

https://github.com/PowerShell/PowerShell/issues/7758

The simplest solution to avoid the keyword conflict is to instead use:

(Get-IniContent -FilePath 'C:\Users\admin\Desktop\indexes.txt').PSBase.Keys

Hope this helps.

Po-temkin commented 1 year ago

Thank you for helpful advice, its works.

Hi Po-temkin,

Some further research has shown that this is an known and open issue.

PowerShell/PowerShell#7758

The simplest solution to avoid the keyword conflict is to instead use:

(Get-IniContent -FilePath 'C:\Users\admin\Desktop\indexes.txt').PSBase.Keys

Hope this helps.

Thank you for helpful advice, its works.