如何使用PowerShell和CSV导入更新AD用户? [英] How can I update AD users using PowerShell and CSV import?

查看:353
本文介绍了如何使用PowerShell和CSV导入更新AD用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此powershell脚本更新AD用户。理想情况下,我将更新一堆属性,但是现在,我只是想让它更新部门,以便我知道它是否正常工作。

I'm trying to use this powershell script to update AD users. Ideally I'll be updating a bunch of attributes, but for now I'm just trying to get it to update the department just so I get tell if it's working.

Import-Module ActiveDirectory  

$dataSource=import-csv "c:\ADupdate.csv"
foreach($dataRecord in $datasource) {
$employeeID=$dataRecord.employeeID

# List of attributes to update
$department=$dataRecord.department

Get-ADUser -SearchBase "ou=Test,ou=OurUsers,ou=Logins,dc=domain,dc=com" -Identity $employeeID -Properties department | Set-ADUser -Replace @{department=$department}

}


推荐答案

弄清楚了我自己的问题。如果其他人感兴趣,这就是我最终使用的...尽管我使用了很多属性。

Figured out my own problem. Here is what I ended up using if anyone else is interested... though I'm using a lot of attributes.

    Import-Module ActiveDirectory  

$users = Import-Csv -Path c:\update.csv

foreach ($user in $users) {
Get-ADUser -Filter "employeeID -eq '$($user.employeeID)'" -Properties * -SearchBase "ou=Test,ou=OurUsers,ou=Logins,dc=domain,dc=com" |
Set-ADUser -employeeNumber $($user.employeeNumber) -department $($user.department) -title $($user.title) -office $($user.office) -streetAddress $($user.streetAddress) -City $($user.City) -state $($user.state) -postalCode $($user.postalCode) -OfficePhone $($user.OfficePhone) -mobile $($user.mobile) -Fax $($user.Fax) -replace @{"extensionAttribute1"=$user.extensionAttribute1; "extensionAttribute2"=$user.extensionAttribute2; "extensionAttribute3"=$user.extensionAttribute3}
}

这篇关于如何使用PowerShell和CSV导入更新AD用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆