Lubchak Lubchak - 4 months ago 34
PowerShell Question

PowerShell reading property file

I need read properties from config file.
I can do it with

ConvertFrom-StringData(Get-Content test.conf | out-String)


But in this file I have param

username=intranet\sysTestAcc


And when it's try to parse it I had error:
Unrecognized escape sequence \s.

How can I fix that with script? I can't change file before running script.

Answer

Replace the \ with \\:

ConvertFrom-StringData ((Get-Content test.conf -Raw) -replace '\\','\\')