Question

I want to do the following:

New-WebVirtualDirectory -Site "Site1" -Name "XX_$args[0]" -physicalPath "c:\sites\XX_$args[0]"

Where "XX_" is a static string and $args[0] is whatever the first argument passed to the script is. Now I know I can "solve" this by creating two variables and then passing those variables to the cmdlet (New-WebVirtualDirectory) but is there any way to concat the static-string and the variable ($args[0]) in-line without the addition two variables?

I tried enclosing them in ( ) (e.g. -Name ("XX_" + $args[0]) ) but with no success.

Was it helpful?

Solution

try:

"XX_$($args[0])" 

the $(..) expand the value of an array variable or a variable's property in the right way when inside a string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top