Powershell parsing a properties file that contains colons

Question:

If I have a .properties file that contains directories (which contain colons):

and then use ConvertFrom-StringData to convert Key=Value pairs from said properties file to a hash table:

Powershell throws an error (doesn’t like colons):

How do you get round this? I’d like to be able to just refer to the directories using the . notation:

Answer:

Colons have nothing to do with the error you get. And yes, it can be achieved using ConvertFrom-StringData but, as already mentioned, you’re feeding it an array instead of a string. Moreover, you need paths with double backslashes in your file because single backslashes are interpreted as escape characters.

Here’s how to fix your code:

Source:

Powershell parsing a properties file that contains colons by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply