Powershell piped strings and variables are inline?

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 what 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 a way to bind a static string and a variable ($ args [0]) on a string without adding two variables?

I have tried including them in () (eg -Name ("XX_" + $ args [0])), but with no success.

+3


source to share


1 answer


try:

"XX_$($args[0])" 

      



$ (..) expand the value of an array variable or variable property correctly within a string.

+6


source







All Articles