If I have a .properties file containing directories (containing colons):
some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
and then use ConvertFrom-StringData to convert the Key = Value pair from the specified properties file to a hash table:
$props_file = Get-Content "F:\dir\etc\props.properties"
$props = ConvertFrom-StringData ($props_file)
$the_dir = $props.'some_dir'
Write-Host $the_dir
Powershell throws an error (doesn't like colons):
ConvertFrom-StringData : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'StringData'. Specified method is not supported.
At line:3 char:32
+ $props = ConvertFrom-StringData <<<< ($props_file)
+ CategoryInfo : InvalidArgument: (:) [ConvertFrom-StringData], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand
How to get around this? I would like to be able to just reference directories using. Designations:
$props.'some_dir'
source
share