首页 > 解决方案 > 使用 PowerShell 使用电子邮件地址更新 AD 中的职位描述

问题描述

我目前正在尝试编写一个 powershell 脚本,该脚本将通过 CSV 文件更新 Active Directory 中各种用户的作业描述

我使用的标识符是用户的电子邮件地址而不是用户名(我认为这会更容易!)

任何人都可以提供帮助,因为我正在努力编写任何有效的有效方法!:(

标签: powershellcsvdirectory

解决方案


好的,假设您的 .csv 看起来像这样:

"email","jobtitle"
"user1@mydomain.com","New job description for user1"
"user2@mydomain.com","New job description for user2"
"user3@mydomain.com","New job description for user3"

然后你可以做类似的事情

Import-Module ActiveDirectory

Import-CSV -Path <PATH-TO-YOUR-CSV-FILE> | Foreach-Object {
    # properties from the csv
    $mail  = $_.email
    $title = $_.jobtitle
    Get-ADUser -Filter {(mail -eq "$mail")} | Set-ADUser -Title $title
}

推荐阅读