Due*_*eli 1 powershell ldap active-directory windows-server-2008-r2
我想用序号填写Active Directory中用户的"employeeID"或"uid".我所做的只是将用户导出为CSV文件:
Get-ADUser -Filter "mail -like '*com'" | Export-Csv 'C:\ADUser.csv' -NoType
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做这样的事情?
这会将所有用户EmployeeID字段从1开始依次设置为一个数字:
Get-ADUser -Filter "mail -like '*com'" | ForEach-Object -Begin {$UserID = 1} {
Set-ADUser $_ -EmployeeID $UserID -WhatIf
$UserID++
}
Run Code Online (Sandbox Code Playgroud)
-WhatIf如果它看起来像你想要的那样,请删除参数.请注意,它可能会替换所有这些用户的任何现有值,并且不会考虑域中其他用户对象可能具有相同ID的可能性(因为您已过滤到具有电子邮件地址的用户).
如果您想在结尾处输出CSV输出结果,您可以进一步执行此操作:
Get-ADUser -Filter "mail -like '*com'" | ForEach-Object -Begin {$UserID = 1} {
Set-ADUser $_ -EmployeeID $UserID -WhatIf
$UserID++
Get-ADUser $_ -Properties Samaccountname,EmployeeID | Select Samaccountname,EmployeeID
} | Export-Csv 'C:\ADUser.csv' -NoType
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
447 次 |
| 最近记录: |