lipkau / PsIni

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

If "=" missing from the ini file, it is ignored #33

Closed Juvls closed 6 years ago

Juvls commented 7 years ago

Hi,

I was trying to use your module to update a nagios conf file, see below an example, and I found out if the "=" is missing (e.g. NRPEListener.dll, CheckWMI.dll) in the .ini file, it is going to be ignored with get-iniContent

Thanks for your module!

[modules]
NRPEListener.dll
NSClientListener.dll
CheckWMI.dll
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
CheckEventLog.dll
CheckHelpers.dll
;# NSCLIENT++ MODULES
;# A list with DLLs to load at startup.
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NRPEListener.dll
;SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
CheckExternalScripts.dll

;# USE THIS FILE
;  Use the INI file as opposed to the registry if this is 0 and the use_reg in the registry is set to 1
;  the registry will be used instead.
use_file=1

[log]
;# LOG DEBUG
;  Set to 1 if you want debug message printed in the log file (debug messages are always printed to stdout when run with -test)
;debug=1

;# LOG FILE
;  The file to print log statements to
file=opsview-agent.log
lipkau commented 7 years ago

What behavior would you expect? An array? Under the Section?

INI files do not support lines without a delimiter.

Juvls commented 7 years ago

I would expect to see them under the array/section modules so when I export the .ini file with my change, it does include everything.

Yes it is not very standard for a INI file and I found an alternative to do it, so maybe it's not worth fixing! :)

    $iniContent = Get-Content $iniFile |
        %{
            $_ -replace 'string_to_search', 'new_string'
        }
    $iniContent | Out-file $iniFile
lipkau commented 6 years ago

I am closing this, as I don't see any benefit for the module supporting this use case. At least for now.