Advertisement
darksim905

Powershell New User Function

May 10th, 2013
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement