如何仅编辑多个用户的名字(givenName)并使用CSV导入 [英] How to edit only the Firstname (givenName) of multiple users and import with csv

查看:93
本文介绍了如何仅编辑多个用户的名字(givenName)并使用CSV导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个用户列表,其中所有用户的samAccountName都是数字,例如745744、745746等…。我正在寻找可以完成以下任务的Powershell脚本:

If I have a list of users where the samAccountName for all the users are all numerical Example, 745744, 745746, etc…. I was looking for a powershell script that could accomplish the following:


  1. 在用户的名字/前面加上一个不带引号的 XX给定名称

  2. 如果我有所有用户samAccountName的列表,请让脚本从csv文件导入用户列表。

在excel中只有一列,而samAccountName足以满足csv的需要,或者我是否还需要让所有用户都获得namedName以及在csv内部?示例列A samAccountName,列B Firstname ??

Is having only one column in excel with the samAccountName sufficient for the csv, or do i need to also have all of the users givenName as well inside of the csv?? Example column A samAccountName, column B Firstname??

示例namedName是JOAQUIN,我需要名字为XXJOAQUIN。我大约有500个用户需要这样做,而现在我们正在手动进行操作,因此,我唯一需要更改的就是在用户namedNames之前添加 XX。

Example givenName is, JOAQUIN, I would need the first name to be XXJOAQUIN. I have about 500 users that I would have to do this for, and we are doing it manually right now, So the only thing that I need changed is adding the "XX" before the users givenNames….

预先感谢大家。

推荐答案

如果CSV文件仅包含带有<$的标头c $ c> samAccountName 后跟类似的samAccountName:

If your CSV file just contains a header with the samAccountName followed by the samAccountNames like this:


samAccountName

745744

745746

samAccountName
745744
745746

然后,您可以使用以下代码,将路径更改为csv的路径与您的用户一起归档。
这可以做得更短,可以更好地使用管道来减少代码,但这会很好。

Then you can use the following piece of code, change the path to the path of the csv file with your users. This could be made shorter and use the pipeline better to make it less code, but this will work just fine.

$users = Import-Csv -Path .\users.csv 

foreach($user in $users) {
$obj = Get-ADUser -Identity $user.samAccountName
Set-ADUser -Identity $user.samAccountName -GivenName ("xx" + $obj.GivenName)
}

这篇关于如何仅编辑多个用户的名字(givenName)并使用CSV导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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