1

我在活动目录中有一个用户列表,我必须删除其中的描述和办公字段。我如何通过 poweshell 进行操作?我试试这个但不工作。

我的代码路径没问题

Import-Module ActiveDirectory
$Users = Import-csv C:\Users\xxxx\Desktop\test.csv
foreach($User in $Users){
Set-ADUser $User.SamAccountName -Description $User.NewDescription
}

我的.csv

SamAccountName;NewDescription;EmailAddress
xxxxxxxxxx;xxxxxxxxxxx;xxxxxxxxxxxxx@libero.it

Powershell 答案

Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the 
argument, and then try running the command again.
At line:4 char:12
+ Set-ADUser $User.SamAccountName -Description $User.NewDescription
+            ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUs 
   er

帮助将不胜感激

4

2 回答 2

1

您需要在import-csv语句中指定分隔符。默认是逗号分隔的,所以你可以这样定义

$Users = Import-csv C:\Users\xxxx\Desktop\test.csv -Delimiter ';'

如果没有这个,那么它将作为一列而不是三列导入。

有关更多信息,请参阅导入 CSV

于 2020-09-29T12:32:59.503 回答
0

它可能有用吗?

$users = Import-Csv -Path C:\users1.csv

foreach ($user in $users) { #在指定的OU中搜索并更新现有属性 Get-ADUser -Filter “SamAccountName -eq '$($user.samaccountname)'” -Properties * -SearchBase “cn=Users,DC=* *********,DC=*****” | Set-ADUser -清除描述,Office }

于 2020-10-02T10:00:44.703 回答