Powershell脚本更新现有用户的Active Directory属性

时间:2018-10-10 03:55:06

标签: powershell

我有一个包含多列的CSV源文件,我想将其中一些(但不是全部)列更新为AD中的匹配用户。

# Import AD Module             
Import-Module ActiveDirectory            

# Import CSV into variable $userscsv            
#$userscsv = import-csv             
$users = Import-Csv -Path 'C:\Scripts\ADUPLOADtest2.csv'           
# Loop through CSV and update users if the exist in CSV file            

foreach ($user in $users)
{            
    #Search in specified OU and Update existing attributes            
    Get-ADUser -Filter "SamAccountName -eq '$($user.Username)'" -Properties * |            
        Set-ADUser -employeeNumber $($user.Emp_Code) -extensionAttribute4 $($user.Cost_Centre) -title $($user.Role) -Department $($user.Work_Area) 
 }

源CSV文件示例:

Emp Code,Username,Surname,Manager,First name,Department,Division,Section,Team,Role,Work Area,Cost Centre
82644,aah,Haven,Peter Jones,April,Executive,Community Wellbeing,General,General,Community Wellbeing Support Officer,Community Wellbeing,50016001

使用上面带有示例CSV的代码,当前在extensionAttribute4字段更新中出现以下错误:

Powershell Error

任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

如错误所示,该参数不存在。您是否尝试过-Set-ADUser -Add @ {attributename =“ TheRequiredValue”}