Warum funktioniert die Syntax von $ hash.key in der ExpandString-Methode nicht?

Das folgende Powershell-Skript veranschaulicht das Problem:

$hash = @{'a' = 1; 'b' = 2}
Write-Host $hash['a']        # => 1
Write-Host $hash.a           # => 1

# Two ways of printing using quoted strings.
Write-Host "$($hash['a'])"   # => 1
Write-Host "$($hash.a)"      # => 1

# And the same two ways Expanding a single-quoted string.
$ExecutionContext.InvokeCommand.ExpandString('$($hash[''a''])') # => 1
$ExecutionContext.InvokeCommand.ExpandString('$($hash.a)')      # => Oh no!

Exception calling "ExpandString" with "1" argument(s): "Object reference not set to an instance of an object."
At line:1 char:1
+ $ExecutionContext.InvokeCommand.ExpandString('$($hash.a)')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

Jeder weiß warum das so ist$hash.key Syntax funktioniert überall, aber in expliziten Erweiterungen? Kann das behoben werden, oder muss ich es aufsaugen und mit dem leben?$hash[''key''] Syntax?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage