简体   繁体   English

Powershell脚本更新Active Directory属性

[英]Powershell script to update Active Directory attribute

I have limited exposure to Powershell so I need some help. 我对Powershell的接触有限,因此需要一些帮助。

I have a CSV file with just the SamAccounName . 我有一个仅SamAccounName的CSV文件。 I would like to use powershell to import that file and update the employeeID attribute with the sammaccountname value. 我想使用sammaccountname导入该文件,并使用sammaccountname值更新employeeID属性。 The import is the easy part: 导入是容易的部分:

$users = Import-Csv c:\filename.csv

Using the file to update the employeeid attribute is what I need help with. 我需要使用文件来更新employeeid属性。 Thanks in advance for your help. 在此先感谢您的帮助。

There is some great documentation about this here so you can get a good idea about this: https://technet.microsoft.com/en-us/library/ee617215.aspx 这里有一些很好的文档,因此您可以对此有所了解: https : //technet.microsoft.com/zh-cn/library/ee617215.aspx

With RSAT Running you need to Import the AD Cmdlet's Import-Module ActiveDirectory 使用RSAT运行,您需要导入AD Cmdlet的Import-Module ActiveDirectory

Once this is done you are starting to head down the appropriate path, try working with the following: 完成此操作后,您将开始尝试适当的方法,尝试使用以下方法:

Import-CSV $csvFile | forEach { Set-ADUser $_.SamAccountName -EmployeeID $_.SamAccountName -WhatIf }

This can go much further, have a look at the top link instead of copying and pasting this code as you don't want to make error on this. 这可以走得更远,查看顶部链接,而不是复制并粘贴此代码,因为您不想在此上出错。 But there should be enough information here to get you up and running. 但是这里应该有足够的信息来帮助您入门和运行。

Note the '-WhatIf' in the above code means PoSh will tell you what will happen rather than making it happen. 请注意,以上代码中的“ -WhatIf”表示PoSh会告诉您将要发生的事情,而不是让它发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM