Want more features on Pastebin? Sign Up, it's FREE!

Powershell New User Function

By: darksim905 on May 10th, 2013  |  syntax: Power Shell  |  size: 0.71 KB  |  views: 299  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function New-Employee
  2. {
  3. do {$UserOU = Read-Host 'User belongs in which site: CA NJ or NY?'}
  4. while (($UserOU -ne 'CA') -and ($UserOU -ne 'NJ') -and ($UserOU -ne 'NY'))
  5. (($UserOU -eq 'CA') -or ($UserOU -eq 'NJ') -or ($UserOU -eq 'NY'))
  6. $OUPath = 'OU=Users,OU='+$UserOU+',OU=Tenehawk,DC=tenehawk,DC=local'
  7.  
  8. Write-Host 'The path the user will be placed in is' $OUPath
  9. $fname = Read-Host 'First name'
  10. $lname = Read-Host 'Last name'
  11. $displayname = $fname + ' ' +  $lname
  12. $upn = Read-Host 'Username'
  13. Write-host 'Display Name:' $displayname
  14.  
  15. New-ADUser -SamAccountName $upn -GivenName $fname -Surname $lname -Name $displayname -Displayname $displayname -AccountPassword (Read-Host "Password" -AsSecureString) -Path $OUPath
  16. }
clone this paste RAW Paste Data