Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a properties file in powershell

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?

like image 780
jos11 Avatar asked Nov 28 '13 22:11

jos11


People also ask

How do you access properties in PowerShell?

To get the properties of an object, use the Get-Member cmdlet. For example, to get the properties of a FileInfo object, use the Get-ChildItem cmdlet to get the FileInfo object that represents a file. Then, use a pipeline operator ( | ) to send the FileInfo object to Get-Member .

How do I read a PowerShell config file?

After loading c:\app. config, we are displaying path of currently loaded configuration file, using CurrentDomain. GetData() method. By following the above steps, we can load and read a custom config file in current app domain within PowerShell script.

How do I read a registry value in PowerShell?

One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .

How do I get folder properties in PowerShell?

The Get-ItemProperty cmdlet gets the properties of the specified items. For example, you can use this cmdlet to get the value of the LastAccessTime property of a file object. You can also use this cmdlet to view registry entries and their values.


1 Answers

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 
like image 66
mjolinor Avatar answered Sep 28 '22 11:09

mjolinor