开发者

Expanding environment variables in active-directory

I'm trying to set a user's profilePath like this:

$commonname = "Firstname lastname"
$samaccountname = "some-user-name"
$user = organizationalUnit.create("user", "CN=$commonname")
$user.invokeset("SamaccountName", $samaccountname)
$user.commitchanges()
$profilePath = "\\domain.local\profiles\%USERNAME%"
$user.invokeset("profilePath", $profilePath)
$user.commitchanges()

When I look at the newly set attribute however, the %USERNAME% variable does not get expanded to "some-use开发者_开发百科r-name". When I type the same profile path in the windows server manager gui for active-directory and click "Apply", it does get expanded.

How can I make the %USERNAME% variable expand?


You can access environment variables via $env:variablename syntax. Like so,

$profilePath = "\\domain.local\profiles\$env:username"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜