This topic contains 4 replies, has 3 voices, and was last updated by
May 18, 2017 at 2:53 pm #71002ParticipantTopics: 11Replies: 6Points: 0Rank: Member
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?
May 18, 2017 at 4:28 pm #71008ParticipantTopics: 0Replies: 10Points: 0Rank: Member
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?
May 18, 2017 at 4:31 pm #71011ParticipantTopics: 33Replies: 128Points: 305Rank: Contributor
in cases like this, I usually encapsulate the parameter in $(), so $($Username)
May 18, 2017 at 6:31 pm #71012ParticipantTopics: 11Replies: 6Points: 0Rank: Member
Adding $($Username) resolved the issue. However, can you explain what $() does?
May 18, 2017 at 6:39 pm #71014ParticipantTopics: 0Replies: 10Points: 0Rank: Member
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
The topic ‘Home Directory’ is closed to new replies.