IsraelTorres

CreateADUser.ps1

Mar 15th, 2012
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Israel Torres
  2. # 2012-03-14
  3. # Create a simple AD user in AD; establish a password; enable account
  4. Import-Module ActiveDirectory
  5. #
  6. # args: username, password
  7. if($args.Length -eq 2){
  8. $username = $args[0]
  9. $password = $args[1]
  10.     if (!(Get-ADUser -filter {SamAccountName -eq $username})) {
  11.         Write-Host "Creating User:$username"
  12.         New-ADUser $username
  13.         Write-Host "Setting User:$username with New Password"
  14.         Set-ADAccountPassword -Identity myTestAdmin -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $password -Force)
  15.         Write-Host "Unlocking User:$username"
  16.         Unlock-ADAccount -Identity $username
  17.         Write-Host "Enabling User:$username"        
  18.         Enable-ADAccount -Identity $username
  19.     }else{
  20.             Write-Host "User: $username already exists; do something else."
  21.     }
  22. }else{
  23.     Write-Host "Usage: .\CreateADUser.ps1 username password"
  24. }
  25. #EOF
RAW Paste Data