2011-06-28 48 views
0

我想设置用户的PROFILEPATH这样的:扩大环境变量

$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() 

当我在新设置的属性看然而,%USERNAME%变量不被扩大到“一些用户名”。当我在windows服务器管理器gui中为active-directory键入相同的配置文件路径,然后单击“应用”时,它确实得到扩展。

如何使%USERNAME%变量扩大?

回答

1

您可以通过$env:variablename语法访问环境变量。像这样,

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

对不起,如果不清楚,但我需要插入(许多)不同于我的名字。 – XORcist

+0

是不是用户名与samaccountname相同? – vonPryz

+0

是的,这就是我现在所使用的方式。 – XORcist