powershell批量管理AD活动目录域用户
程序员文章站
2023-12-30 15:20:52
...
创建用户
Import-Csv c:\users\y\desktop\powershell\创建模板.txt | foreach {New-ADUser -Name $_.name -DisplayName $_.displayname -Description $_.description -UserPrincipalName $_.userprincipalname -SamAccountName $_.samaccountname -AccountExpirationDate $null -Company $_.company -Department $_.department -Title $_.title -Path $_.path -AccountPassword (ConvertTo-SecureString "Abc123" -AsPlainText -Force) -PasswordNeverExpires $true -Enabled $true}
Import-Csv c:\users\y\desktop\powershell\群组.csv | foreach {Add-adgroupmember -Identity $_.Group -members $_.Name}
创建模板.txt
群组.csv
更改属性
Import-Csv c:\users\y\desktop\powershell\更改描述.txt | foreach {Set-ADUser -Identity $_.name -DisplayName $_.displayname -Description $_.description}
更改描述.txt
查询
$a=Get-Content -Path c:\users\y\desktop\powershell\description.txt
foreach($i in $a){
$b=(Get-ADUser -Filter {Description -like $i} -SearchBase "OU=SHYK,OU=组织机构,DC=sinopec,DC=ad" | Select name) >>c:\users\y\desktop\查询描述.txt
}
description.txt (精确或模糊匹配)