powershell - 用于更新现有用户的 Active Directory 属性的 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 字段更新中收到以下错误:
任何建议将不胜感激。
解决方案
正如错误所说,该参数不存在。你有没有尝试过 - Set-ADUser -Add @{attributename="TheRequiredValue"}
推荐阅读
- python - BertForMultipleChoice 假定哪个选项最正确?
- gremlin - 从 gremlin-server 保存的 GraphML 被重复的 id 损坏
- typescript - 如何为包含已知未知键的递归对象声明类型
- node.js - 部署到heroku并响应前端根本不起作用
- java - spring boot config客户端无法使用bootstrap.properties从配置服务器加载配置
- python - Python海龟文件“
",第 5 行,在笔下 - c# - '无法从节点连接读取描述符:' C# VS Code 2019 项目中的错误
- python - 如何获取名称和首选项字符串并将它们添加到以名称为键的字典中?
- python - 如何创建具有排列的行和列的二维列表(矩阵)
- mysql - 在 MySQL 中按时间线性分布的样本 n 行