且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell管理系列(二十八)PowerShell操作之修改AD账号密码

更新时间:2022-06-30 21:45:41

有一群友问,我有一个表格,里面有我需要修改密码的账号和密码,如何批量操作呢?步骤如下:

步骤1、我们先创建好表格,表格分两列,分别是人员姓名和密码,也可以从powershell里面导出来,命令行如下:

Import-Module activedirectory

get-aduser -SearchBase "ou=test,dc=yuntcloud,dc=com" -filter *|Select-Object name,samaccountname| `

Export-Csv -Path c:\userinfo.csv -Encoding utf8 -NoTypeInformation

Powershell管理系列(二十八)PowerShell操作之修改AD账号密码

步骤2、我们将导出的csv新增一列"password",并填充需要需要的密码

Powershell管理系列(二十八)PowerShell操作之修改AD账号密码

technte语法参考如下:

https://technet.microsoft.com/zh-cn/library/ee617261.aspx

步骤3、导入csv表格,并批量修改密码

import-csv -path c:\userinfo.csv |%{Set-ADAccountPassword -identity $_.samaccountname -Reset `

-NewPassword (ConvertTo-SecureString -AsPlainText $_.password -Force)}

也可以

import-csv -path c:\userinfo.csv |%{get-aduser -identity $_.samaccountname |Set-ADAccountPassword  -Reset `

-NewPassword (ConvertTo-SecureString -AsPlainText $_.password -Force)}

Powershell管理系列(二十八)PowerShell操作之修改AD账号密码



本文转自 zhou_ping 51CTO博客,原文链接:http://blog.51cto.com/yuntcloud/1722442,如需转载请自行联系原作者