How to use variables in path string

AATester 26 Reputation points
2022-02-24T10:01:27.96+00:00

Hello , new to Powershell.

I have a variable $var = "5.3"

and I need to save a string in another variable like below:

$Apath= "C:\Program Files\Test\V $var\My Folder

Here I need to basically concatenate V with 5.3, so the result will be V5.3, but the PS console does not accept it and throws error. How to use variables in the path.

Thanks

Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-02-24T20:24:09.223+00:00

    Hi @AATester ,

    this will work as well (Write-Output isn't required):

    $var = "5.3"  
    $Apath= "C:\Program Files\Test\V $var\My Folder"  
    $Apath  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.