Import-Module ActiveDirectory foreach($i in 1..500) { $TemplateAccountName = "User{0:000}" -f $i # Örnek: User001, User002, User003... $Password = Convertto-secureString -string "Abcd.1234" -AsPlainText New-ADUser -Name $TemplateAccountName -AccountPassword $Password -Path "CN=USERS,DC=siberblog,DC=org" -Enabled:$true } |
Kodu biraz geliştirebiliriz. Kullanıcıya ait bilgilerden hangilerine ihtiyaç duyuluyor ise onları seçebiliriz.
Script Versiyon 1 (ActiveDirectoryAutoUsersAdd_V1.ps1) Kaynak Kod:
# =========================================================== # NAME: ActiveDirectoryAutoUsersAdd_V1.ps1 # AUTHOR: Bekir Yalçın # DATE: 22/01/2015 # COMMENT: Aktif Dizine belirlenen sayıda otomatik olarak kullanıcı ekleme. # VERSION: 1 # LINK: http:/siberblog.org/index.php/active-directory-create-multiple-test-user-accounts-using-powershell # =========================================================== Clear if(Get-Module -ListAvailable | Where-Object { $_.name -eq "ActiveDirectory" }) { Import-Module ActiveDirectory } else { Write-Host "Bu script sadece DC üzerinde çalıştırılabilir." -foregroundcolor RED break } #$ErrorActionPreference = "SilentlyContinue" $ReportLogFile = ( "UsersAdd" + (Get-Date –f "_yyyyMMdd_HHmmss").tostring() + ".csv" )# =================================================== # Ön tanımlamalar [int]$TotalUsers = (Read-Host "Kaç adet kullanıcı oluşturulacak")$AccountPassword = "Aa12345" $ChangePasswordAtLogon = $false $Company = "MERCAN YAZILIM" $Enabled = $true $MobilePhone = "0 555 123 45 67" $Title = "Engineer" #$path = "CN=Users,DC=siberblog,DC=org" $state = "County" $firstname = "Bekir" $surname = "Yalçın" $department = "Yazılım Birimi" $description = "Test user...siberblog.org..." $office = "Powershell" # =================================================== # Kullanıcı Eklemeye Başla for ($i=0; $i -lt $TotalUsers; $i++) { $UserID = "{0:0000}" -f ($i + 1) $UserName = "User" + $UserID #Örnek UserName= User0001 $EmailAddress = "$UserName@siberblog.org"$DisplayName = "$firstname $surname" $userprincipalname = $EmailAddress $SamAccountName = $UserName $givenname = $firstname $Name = $firstname + " " + $surname + " " + $UserID # CN $PasswordNeverExpires = $true New-ADUser -AccountPassword (ConvertTo-SecureString $AccountPassword -AsPlainText -Force) ` -PasswordNeverExpires $PasswordNeverExpires ` -ChangePasswordAtLogon $false ` -Company $Company ` -DisplayName $DisplayName ` -Enabled $true ` -MobilePhone $MobilePhone ` -Name $name ` -SamAccountName $SamAccountName ` -Title $Title ` -state $state ` -givenname $givenname ` -surname $surname ` -userprincipalname $userprincipalname ` -department $department ` -description $description ` -office $office ` -EmailAddress $EmailAddress -PassThru # -Path $Path Write-Host "Yeni AD kullanıcısı" ($i + 1) "of" $TotalUsers "=" $UserName -foregroundcolor RED Add-Content -Path $ReportLogFile -Value "$UserName;$DisplayName;$firstname;$surname;$EmailAddress" } |
Download Script Versiyon 1: ActiveDirectoryAutoUsersAdd_V1.rar
DİKKAT: Çok daha gelişmiş bir script için; Csv dosyadan okuyarak OU, Kullanıcı Grubu, Kullanıcı Hesabı ekleme veya Kullanıcı Hesabı güncelle scripti için aşağıdaki linke gidebilirsiniz.
http://siberblog.org/index.php/active-directory-easy-import-csv-users-groups-and-ou-insert-into-using-powershell
Hiç yorum yok:
Yorum Gönder