Home Directory

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Bryce McDonald Bryce McDonald 1 month ago.

  • Author
    Posts
  • #71002
    Profile photo of Chad Nathan Jones
    Chad Nathan Jones
    Participant

    This doesn't work...

    $Username = "dweatherston"
    set-aduser $Username -HomeDirectory "\\domain\Users\site\$Username" -HomeDrive u:
    

    But this does

    set-aduser dweatherston -HomeDirectory "\\domain\Users\site\$Username" -HomeDrive u:
    

    Why can't I use a variable next to set-aduser?

  • #71008
    Profile photo of Bryce McDonald
    Bryce McDonald
    Participant

    Hey there! I just tested this in my environment and I'm able to get this to work. Is it possible that in your variable, something is misspelled, or you're inputting a user that doesn't exist?

  • #71011
    Profile photo of iain Barnetson
    iain Barnetson
    Participant

    in cases like this, I usually encapsulate the parameter in $(), so $($Username)

  • #71012
    Profile photo of Chad Nathan Jones
    Chad Nathan Jones
    Participant

    Adding $($Username) resolved the issue. However, can you explain what $() does?

    • #71014
      Profile photo of Bryce McDonald
      Bryce McDonald
      Participant

      Basically it evaluates the value inside of the expression rather than the expression itself. Take the following code for instance:

      $array = @("a","b","c")
      $output = "$arr.length"
      Write-Output $output

      Is going to give you vastly different results than:

      $array = @("a","b","c")
      $output = "$($arr.length)"
      Write-Output $output

You must be logged in to reply to this topic.