展开字符串变量通过Powershell中的单引号存储

时间:2014-12-01 10:42:43

标签: powershell variable-expansion remote-execution

我有一个场景,我需要构建一个PowerShell路径为$RemotePath = '$($env:USERPROFILE)\Desktop\Shell.lnk'。此变量将传递到需要执行的远程计算机。远程机器将其作为字符串变量接收。如何展开字符串以评估$env:USERPROFILE

2 个答案:

答案 0 :(得分:4)

远程方

Expand the string

$ExecutionContext.InvokeCommand.ExpandString($RemotePath)

答案 1 :(得分:1)

使用双引号。 PowerShell不会在单引号字符串中扩展变量。