Если у меня есть файл .properties, содержащий каталоги (содержащие двоеточия):
some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
а затем используйте ConvertFrom-StringData для преобразования пар Key = Value из указанного файла свойств в хеш-таблицу:
$props_file = Get-Content "F:\dir\etc\props.properties"
$props = ConvertFrom-StringData ($props_file)
$the_dir = $props.'some_dir'
Write-Host $the_dir
Powershell выдает ошибку (не любит двоеточия):
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
Как это обойти? Я хотел бы иметь возможность просто ссылаться на каталоги, используя расширение. обозначение:
$props.'some_dir'