AD PowerShell for Add Account & OU & Group

前端之家收集整理的这篇文章主要介绍了AD PowerShell for Add Account & OU & Group前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Create OUs with PS

Import-csv c:\AddOU.csv | New-ADOrganizationalUnit –PassThru

Refer to:
https://www.petri.com/creating-active-directory-ous-powershell

Create Groups with PS

Import-Csv C:\AddGroups.csv | foreach {New-ADGroup -Name $_.Name -ManagedBy $_.ManagedBy -GroupCategory $_.GroupCategory -GroupScope $_.GroupScope -Path $_.OU -Description $_.description}

Create AD accounts with PS

Import-module ActiveDirectory 
Import-Csv "C:\scripts\addusers.csv" | ForEach-Object {
New-ADUser -Name $_.Name -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName -EmailAddress $_.EmailAddress -Description $_.Description -Office $_.Office -Company $_.Company -Department $_.Department -Title $_.Title -Manager $_.Manager -OfficePhone $_.OfficePhone -Country $_.Country -State $_.State -City $_.City -Path $_.Path -AccountPassword(ConvertTo-SecureString -AsPlainText $_.AccountPassword -Force) -Enabled 1 -ChangePasswordAtlogon 0 -PasswordNeverExpires 1}

注意点:
1)CSV要以UTF-8保存,不然中文会乱码
2)为账号添加Manager时,Manger的账号必须已经存在DC中,不然会报错
2)Enable 1,数字1表示启用账户,ChangePasswordAtlogon 0,数字0表示下一次登录不需要修改密码,PasswordNeverExpires 1,数字1表示密码永不过期。

Add Users to Group using PS

#Add Users to a Group - PowerShell Script

Import-module ActiveDirectory 
Import-CSV "C:\Scripts\Users.csv" | % { 
Add-ADGroupMember -Identity $_.GroupName -Member $_.UserName 
}
原文链接:https://www.f2er.com/windows/372888.html

猜你在找的Windows相关文章