如何解决使用employeeid更新员工经理
因此,我正在进行一个项目,该项目将根据我们的人力资源系统,根据审核的要求每周更新一些员工信息。我从HR那里获得的唯一唯一匹配字段是employeeID(对于用户和经理)。我没有问题,让Get-ADUser拉起雇员并更新这些字段,但是现在我还需要使用其雇员ID更新雇员的经理。我不确定如何获得强大的功能来将经理雇员ID转换为他们的UPN或其他方法来提取他们的信息。这是我的代码
Import-Module ActiveDirectory
$Users = Import-csv "C:\Users\my.stuff\stuff\TitlePowershell.csv"
foreach($User in $Users) {
Get-ADUser -Filter {EmployeeID -eq $user.employeeID}
| Set-ADUser -replace @{description=$User.description; title=$User.title; manager=$user.ManagerID}
}
我可以添加些什么来使经理从其员工ID中进行更新?
解决方法
用户的Manager
属性包含该用户的DistinguishedName
。
由于显然在CSV文件中,您拥有该经理的EmployeeID
,因此您需要做一些额外的工作来获取DN
尝试
Import-Module ActiveDirectory
$Users = Import-csv "C:\Users\my.stuff\stuff\TitlePowershell.csv"
foreach($User in $Users) {
# get the user object for the manager
$usr = Get-ADUser -Filter "EmployeeID -eq '$($user.employeeID)'" -ErrorAction SilentlyContinue
if ($usr) {
# get the user object for the manager
$mgr = Get-ADUser -Filter "EmployeeID -eq '$($user.ManagerID)'" -ErrorAction SilentlyContinue
if ($mgr) {
$usr | Set-ADUser -Replace @{Description = $User.description; Title = $User.title; Manager = $mgr.DistinguishedName}
}
else {
Write-Warning "No manager found with EmployeeID $($user.ManagerID)"
}
}
else {
Write-Warning "No user found with EmployeeID $($user.employeeID)"
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。