Advertisement
infolookup

Untitled

Aug 31st, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Import file and populate user fields
  2. Function ReadCSV
  3.  {
  4.      Param([string]$fileName)
  5.      $users = Import-Csv $fileName
  6.      foreach ($user in $users){
  7.          $flln = $user.'last name'.ToUpper().Substring(0)
  8.          $db = ""
  9.          if(($flln.CompareTo("A") -ge 0) -and ($flln.CompareTo("F") -le 0)){
  10.             $db = "Student Store A-F"
  11.          }
  12.          elseif($flln.CompareTo("G") -ge 0 -and $flln.CompareTo("M") -le 0){
  13.             $db = "Student Store G-M"
  14.          }
  15.          else{
  16.             $db = "Student Store N-Z"
  17.          }
  18.          $ht  = @{
  19.              'givenName'=$user.'first name'
  20.              'sn'=$user.'last name'
  21.              'displayName'= ($user.'first name' + " " + $user.'last name')
  22.              'name' = ($user.'first name' + " " + $user.'last name')
  23.              'alias'= ($user.'first name' + "." + $user.'last name')
  24.              'samAccountName'= ($user.'first name' + "." + $user.'last name')
  25.              'userPrincipalName' = ($user.'first name' + "." + $user.'last name' +"@mycollege.edu")
  26.              'organizationalUnit' = "OU=Staging,OU=Student Accounts,DC=mycollege,DC=edu"
  27.              'retentionPolicy' = "Student Policy"
  28.              'office' = $user.office
  29.              'database' = $db
  30.          }
  31.          Write-Output $ht
  32.      }
  33.  }
  34.  
  35. # User creation portion
  36. Function CreateUser{
  37.  Param($userInfo)
  38.  $secureString = ConvertTo-SecureString "Changeme123" -AsPlainText –Force
  39.  New-Mailbox  -Name $userInfo['name' ]`
  40.  -Alias $userInfo['alias'] -UserPrincipalName $userInfo['userPrincipalName']`
  41.  -SamAccountName $userInfo['alias'] -Database $userInfo['Database']`
  42.  -FirstName $userInfo['givenName'] -LastName $userInfo['sn']`
  43.  -OrganizationalUnit $userinfo['organizationalUnit']`
  44.  -RetentionPolicy $userInfo['retentionPolicy']`
  45.  -DisplayName $userInfo['DISPLAYNAME'] -Password $secureString -ResetPasswordOnNextLogon $true
  46.   }
  47.  
  48. #Create mailbox
  49. Function CreateMailbox{
  50.  PROCESS
  51.  {
  52.  CreateUser $_
  53.  }
  54. }
  55.  
  56.  ReadCSV C:\\MailboxMove\Test.csv | CreateMailbox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement