1. ConvertFrom-StringData
https://msdn.microsoft.com/powershell/reference/4.0/microsoft.powershell.utility/convertfrom-stringdata
- # 注意路径中的反斜线需要转义
-
- $str = @"
- Username=hello1
- Password=world1
- Path=C:\\test
- "@
-
- $hash = ConvertFrom-StringData $str
- $hash.Keys
- $hash.Values
复制代码
2. Invoke-Expression
https://msdn.microsoft.com/powershell/reference/4.0/microsoft.powershell.utility/invoke-expression
- $str = "@{
- Username='hello2'
- Password='world2'
- Path='C:\test'
- }"
-
- $hash = Invoke-Expression $str
- $hash.Keys
- $hash.Values
复制代码
|