Read a properties file in powershell

jos11 picture jos11 · Nov 28, 2013 · Viewed 28.8k times · Source

Let's suppose that I have a file.properties and its content is:

app.name=Test App
app.version=1.2
...

how can I get the value of app.name?

Answer

mjolinor picture mjolinor · Nov 29, 2013

You can use ConvertFrom-StringData to convert Key=Value pairs to a hash table:

$filedata = @'
app.name=Test App
app.version=1.2
'@

$filedata | set-content appdata.txt

$AppProps = convertfrom-stringdata (get-content ./appdata.txt -raw)
$AppProps

Name                           Value                                                                 
----                           -----                                                                 
app.version                    1.2                                                                   
app.name                       Test App                                                              

$AppProps.'app.version'

 1.2