为什么我会收到此 Powershell 哈希文字不完整错误?

Why am I getting this Powershell hash literal was incomplete error?

我正在尝试在 PowerShell 中设置哈希table(字典)。当我尝试这条线时:

$users = @{abertram = 'Adam Bertram' raquelcer = 'Raquel Cerillo' zheng21 = 'Justin Zheng'}

我收到以下错误:

At line:1 char:38
+ $users = @{abertram = 'Adam Bertram' raquelcer = 'Raquel Cerillo' zhe ...
+                                      ~~~~~~~~~
Unexpected token 'raquelcer' in expression or statement.
At line:1 char:37
+ $users = @{abertram = 'Adam Bertram' raquelcer = 'Raquel Cerillo' zhe ...
+                                     ~
The hash literal was incomplete.
At line:1 char:91
+ ... 'Adam Bertram' raquelcer = 'Raquel Cerillo' zheng21 = 'Justin Zheng'}
+                                                                         ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

为什么我会得到这个以及如何在 PowerShell 中正确设置哈希 table?

您必须在同一行上用分号分隔 Key/Value 对 ;

$users = @{abertram = 'Adam Bertram'; raquelcer = 'Raquel Cerillo'; zheng21 = 'Justin Zheng'}

虽然使用新行可能更可取:

$users =
@{
    abertram = 'Adam Bertram'
    raquelcer = 'Raquel Cerillo'
    zheng21 = 'Justin Zheng'
}