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?
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?
in cases like this, I usually encapsulate the parameter in $(), so $($Username)
Adding $($Username) resolved the issue. However, can you explain what $() does?
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