导入单个AD用户命令
New-ADUser -Name "周八" -Surname "周" -GivenName "八"-SamAccountName "20160219008" -UserPrincipalName "[email protected]" -DisplayName "周八" -Description "周八" -Path "OU=资金处,OU=财务部,OU=开发公司,DC=KFGS,DC=COM,DC=CN" -AccountPassword(ConvertTo-SecureString "567@test" -AsPlainText -force ) -Enabled $true -ChangePasswordAtLogon $false
New-ADUser -Name "周八" -Surname "周" -GivenName "八" -UserPrincipalName "[email protected]" -Path "OU=资金处,OU=财务部,OU=开发公司,DC=KFGS,DC=COM,DC=CN" -AccountPassword(ConvertTo-SecureString "567@test" -AsPlainText -force ) -Enabled $true -ChangePasswordAtLogon $false
批量导入用户
Import-Csv 'C:\user.csv' | ForEach-Object{New-ADUser -SamAccountName $_.SamAccountName -Surname $_.Surname -GivenName $_.GivenName -Name $_.Name -Group $_.Group -UserPrincipalName $_.UserPrincipalName -Path $_.Path -AccountPassword(ConvertTo-SecureString -AsPlainText $_.AccountPassword -Force) -Enabled 1 -ChangePasswordAtLogon 1}
表格的格式
注意点:CSV要以UTF-8保存,不然中文会乱码,执行命令会报错,我就深受其害。自己要清楚模版所对应的参数,不要填写错误。Enable 1,数字1表示启用账户,ChangePasswordAtLogon 1,数字1表示下一次登录需要修改密码。如果都改为数字0表示禁用账户,下一次登录不需要修改密码
Get-ADUser -Filter * -SearchBase "ou=小的ou,ou=大的ou,dc=小的dc,dc=大的dc" | Select-Object -Property Name | Export-Csv -Encoding unicode xx.csv
获取AD用户 过滤 搜索底部 组织单位 组织单位 域控 选择对象 属性 用户名 导出csv 编码 csv档案名
批量导出AD用户
Get-ADUser -Filter * -SearchBase "DC=KFGS, DC=COM, DC=CN" |Select-Object -Property SamAccountName, Surname, GivenName, Name, Group, UserPrincipalName, Path, AccountPassword, Enabled, ChangePasswordAtLogon | Export-Csv -Encoding unicode ADuser.csv