3

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.