2020/09/14 #連想配列(hashtable)を作る
皆様おはようございます、
#猫でもできるPowerShell(備忘録)#連想配列(hashtable)を作る
<# 元ネタ
https://docs.microsoft.com/ja-jp/powershell/module/microsoft.powershell.utility/convertfrom-stringdata?view=powershell-6
#>
$Here = @'
Msg1 = The string parameter is required.
Msg2 = Credentials are required for this command.
Msg3 = The specified variable does not exist.
'@
ConvertFrom-StringData -StringData $Here
Name Value
---- -----
Msg3 The specified variable does not exist.
Msg2 Credentials are required for this command.
Msg1 The string parameter is required.
ヒア文字列の中に書いた keyと valueのペアから連想配列を作ります。
$Here = @{
'Msg1' = 'The string parameter is required.'
'Msg2' = 'Credentials are required for this command.'
'Msg3' = 'The specified variable does not exist.'
}
と書いても同じ結果なのですが、シングルクオート(もしくはダブルクオート)
を連採するよりは自然に書けそうです。
ではまた;
"