PowerShell Active Directory用户更新

我试图更新CSV中所有用户的-msDS-cloudExtensionAttribute。

CSV示例

AD CA11 CA10 CA9 User1 none none technician User2 none engineer technician User3 responsible engineer technician User4 none none none User5 none none none User6 responsible none technician User7 none none none User8 none engineer none User9 none none none User10 none none technician 

我使用set-ADUSer,但它不能识别属性。

 Import-CSV c:\temp\all.csv | Foreach { Set-ADUSer -Identity $_.AD -Add -msDS-cloudExtensionAttribute10 $_.CA10 -msDS-cloudExtensionAttribute11 $_.CA11 -msDS-cloudExtensionAttribute9 $_.CA9 } 

错误:

 A parameter cannot be found that matches parameter name 'msDS-cloudExtensionAttribute10' 

我也尝试join – 添加到命令,但是我得到一个不同的错误。

 Missing an argument for parameter 'Add'. Specify a parameter of type 'System.Collections.Hashtable' 

你的问题是Set-ADUser没有为你可以设置的每个可能的属性定义显式的参数。 相反,你有一些像-Add-Replace这样的参数,它们需要一个key / value对的散列表。

在你的情况下,我可能会使用 – -Replace这样的。

 $csv = Import-CSV C:\temp\all.csv $csv | foreach { Set-ADUser $_.AD -Replace @{'msDS-cloudExtensionAttribute10'=$_.CA10; 'msDS-cloudExtensionAttribute11'=$_.CA11; 'msDS-cloudExtensionAttribute9'=$_.CA9} }