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?
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 .
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.
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With