问题描述
foreach ($Person in $People) {
$NewUserParams = @{
Name = $Person.Name
Server = 'xxxx.com:389'
Path = 'CN=Users,CN=addressBook,DC=xxxx,DC=com'
Credential = $Credentials
givenName = $Person.givenName
otherAttributes = @{sn=$Person.sn}
}
New-ADUser @NewUserParams
}
我想添加许多其他属性(otherAttributes),这些属性可以在formart New-ADUser -Name XXX -OtherAttributes @ {sn = xxx}中使用。但是,我试图使用splatting来使OtherAttributes以及其他必需的参数更具可读性。我不需要在整个命令中使用splatting,我的目标是分解otherAttributes,因此它不是一个长字符串。
I have many additional attributes (otherAttributes) that I would like to add that are available to me in the formart New-ADUser -Name XXX -OtherAttributes @{sn=xxx} . However, I am trying to using splatting to make the OtherAttributes more readable, along with other required parameters. I don't need to using splatting for the entire command, my goal was to break up otherAttributes so it wasn't a long string that wrapped. Ideas?
推荐答案
otherAttributes
的值只是另一个哈希表,并且可以像任何其他哈希表一样包装:
The value of otherAttributes
is just another hashtable, and can be wrapped like any other hashtable:
$NewUserParams = @{
'Name' = $Person.Name
'Server' = 'server.example.com:389'
'Path' = 'cn=Users,cn=addressBook,dc=example,dc=com'
'Credential' = $Credentials
'givenName' = $Person.givenName
'otherAttributes' = @{
'sn' = $Person.sn
}
}
个人而言,我建议将哈希表的键放在引号中以免引起意外,但至少在上面的示例中这不是必需的
Personally, I recommend putting the keys of the hashtables in quotes to avoid surprises, but at least in the above example that's not required.
如果上述方法不起作用,则需要提供有关您正在运行的代码以及所遇到的错误的更多详细信息。在循环内显示生成的哈希表的内容通常有助于解决具有特定值的问题。
If the above doesn't work for you you need to provide more details about the code you're running and the error(s) you're getting. Displaying the content of the generated hashtable inside the loop usually helps troubleshooting problems with particular values.
这篇关于New-ADUser + Other属性,带有可读性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!