【问题标题】:Active directory delete description and office fields through powershell活动目录通过powershell删除描述和office字段
【发布时间】:2020-09-29 11:49:37
【问题描述】:

我在 Active Directory 中有一个用户列表,我必须删除其中的描述和办公室字段。我如何通过 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

我们将不胜感激

【问题讨论】:

    标签: powershell active-directory field-description


    【解决方案1】:

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

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

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

    请参阅Import-CSV 了解更多信息。

    【讨论】:

      【解决方案2】:

      它可能有用吗?

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

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

      【讨论】:

        猜你喜欢
        • 2011-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-09
        • 1970-01-01
        • 2010-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多