INI file parsing in PowerShell

前端 未结 7 1215
[愿得一人]
[愿得一人] 2020-11-27 05:16

I\'m parsing simple (no sections) INI file in PowerShell. Here code I\'ve came up with, is there any way to simplify it?

convertfrom-stringdata -StringData (         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:12

    Don Jones almost had it right. Try:

    ConvertFrom-StringData((Get-Content .\deploy.ini) -join "`n")
    

    -join converts the Object[] into a single string, with each item in the array separated by a newline char. ConvertFrom-StringData then parses the string into key/value pairs.

提交回复
热议问题