Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Powershell concat字符串和变量内联?_String_Powershell_Cmdlet - Fatal编程技术网

String Powershell concat字符串和变量内联?

String Powershell concat字符串和变量内联?,string,powershell,cmdlet,String,Powershell,Cmdlet,我想做以下工作: New-WebVirtualDirectory -Site "Site1" -Name "XX_$args[0]" -physicalPath "c:\sites\XX_$args[0]" 其中,“XX_389;”是一个静态字符串,$args[0]是传递给脚本的第一个参数。现在我知道我可以通过创建两个变量,然后将这些变量传递给cmdlet(New-WebVirtualDirectory)来“解决”这个问题,但是有没有办法在不添加两个变量的情况下将静态字符串和变量($args[

我想做以下工作:

New-WebVirtualDirectory -Site "Site1" -Name "XX_$args[0]" -physicalPath "c:\sites\XX_$args[0]"
其中,“XX_389;”是一个静态字符串,$args[0]是传递给脚本的第一个参数。现在我知道我可以通过创建两个变量,然后将这些变量传递给cmdlet(New-WebVirtualDirectory)来“解决”这个问题,但是有没有办法在不添加两个变量的情况下将静态字符串和变量($args[0])连成一行

我尝试将它们封装在()中(例如-Name(“XX_”+$args[0]),但没有成功

试试看:

"XX_$($args[0])" 
$(..)在字符串中以正确的方式展开数组变量或变量属性的值