在 powershell 中读取属性文件 [英] Read a properties file in powershell
本文介绍了在 powershell 中读取属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个 file.properties 并且它的内容是:
Let's suppose that I have a file.properties and its content is:
app.name=Test App
app.version=1.2
...
如何获取 app.name 的值?
how can I get the value of app.name?
推荐答案
您可以使用 ConvertFrom-StringData 将 Key=Value 对转换为哈希表:
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
这篇关于在 powershell 中读取属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文