PowerShell: Join-Path with a normal string in between RRS feed

  • Frage

  • Hello, I have the following problem.

    In my script I have the following line:

    $userfolder = "\\$NewServer\Users$\$($ADUser.sAMAccountname)" 
    My problem here is that I can't make two variables at that. So for an example if I write only one:

    $userfolder = "\\AD2019\Users$\$($ADUser.sAMAccountname)" 

    It works perfect. I saw that Join-Path could help, but at the middle I have "Users$" what is not a variable.

    How can I do a Join-Path with that construction?

    Dienstag, 18. Juni 2019 08:06

Alle Antworten

  • Where do you get "User$" or what should be done with this?

    You have a lot of Environmentvariables to get the current Userpath and to get an environmentcontent use simply $Env:Variablename.

    Dienstag, 18. Juni 2019 11:30
  • Moin, du hat im ersten Beispiel das erste Dollar-Zeichen mit dem Backslah escaped.

    Evgenij Smirnov

    Dienstag, 18. Juni 2019 11:44
  • Einer der Gründe, das lieber so zu machen:

    $userfolder = '\\{0}\Users$\{1}' -f $NewServer, $ADUser.sAMAccountname

    Greetings/Grüße, Martin - Mal ein gutes Buch über GPOs lesen? - Good or bad GPOs? My blog - And if IT bothers me? Coke bottle design refreshment -

    Dienstag, 18. Juni 2019 14:42