I'm trying to retrieve a parameter value from a config a file.
(Get-Content C:\<ConfigFolder>\basic.conf | ConvertFrom-StringData)."FileLocation"
The value of the "FileLocation" is "C:\temp".
And, value printed on screen is;
"C: emp"
Looks like "\t" is parsed as a Tab.
Is there a way avoid this and print the as original value as is?
File content is as below;
UpdatedTime="2024-03-26 09:55:00"
FileLocation="C:\temp"
zett42 has provided the crucial pointer:
From the
ConvertFrom-StringDatahelp topic (emphasis added), as of PowerShell 7.4.x:Therefore, assuming that all
\characters in your input file are meant to be interpreted literally:Note the use of
-RawwithGet-Contentto ensure that the file content is read in full, as a single, (typically) multiline string, which in turn ensures thatConvertFrom-StringDataoutputs a single[hashtable]instance.(If, by contrast, you really mean to output a separate hashtable for each input line, omit
-Raw).Given that this escaping need may be inconvenient (and possibly somewhat unexpected, but that cannot be helped), it would be helpful if
ConvertFrom-StringDataitself supported verbatim (literal) parsing by way of an opt-in:-Rawswitch. This enhancement has been green-lit, but is yet to be implemented.