gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:53:20 24 4
gpt4 key购买 nike

我有一个包含多列的源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

任何建议将不胜感激。

最佳答案

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

关于powershell - Powershell脚本更新现有用户的Active Directory属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52732384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com