powershell,如何在数组@中扩展变量

powershell, how to expand variable inside array @

我在使用以下代码时遇到问题:

$result = "F651F545A059588ABFDCE7EE3EEB27EED8CED28D"
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="my.host.winagent"; CertificateThumbprint="$result"}'

它产生:

Message = The WS-Management service cannot process the configuration request because the certificate thumbprint in the request is not a valid hex string: $result.

看起来变量结果没有展开,可能是因为它在数组中?如何让变量值在那里展开?

您需要使用 "(而不是 ')来创建可扩展的字符串文字 - 通过加倍转义文字 "

winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=""my.host.winagent""; CertificateThumbprint=""$result""}"