批量创建AD测试账号

在现场中,有时候客户会要求做一下AD压力测试,需要批量创建很多AD用户。奉献此代码供各位参考。
 
   1:  <#
   2:   
   3:  .DESCRIPTION 
   4:  批量创建AD测试账号
   5:   
   6:  #> 
   7:   
   8:  $Text = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
   9:  $PasswordText = ConvertTo-SecureString "Password01!" -AsPlainText -Force
  10:  for ($index = 0; $index -le 10000; $index++) {
  11:      $user = ($Text.ToCharArray()|Get-Random -count 5) -join $null 
  12:      New-ADUser -Name "$user" -SamAccountName "$user" -GivenName "$user" -Surname "$user" `
  13:      -Path "OU=test,DC=contoso,DC=com" -DisplayName ("Mr" + "." + "$user") `
  14:      -AccountPassword $PasswordText -CannotChangePassword $false `
  15:      -ChangePasswordAtLogon $true  -UserPrincipalName ("$user" + "@" + "contoso.com")
  16:      Write-Progress -Activity "Create 10000 AD User" -Status "Completed: $index" -PercentComplete ($index/100)
  17:      Start-Sleep -Milliseconds 1
  18:  }
posted @ 2013-08-28 09:43  motools  阅读(620)  评论(0编辑  收藏  举报