Advertisement
Guest User

mailboxpsloop

a guest
Feb 15th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. ## Create Session with Exchange 2010 change your URI address
  2. $s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://contoso/powershell -Authentication Kerberos
  3.  
  4. Import-PSSession -Session $s
  5. ## Add AD Cmdlets
  6. Import-Module ActiveDirectory
  7. #Import CSV
  8.  
  9. $csv = @()
  10. $csv = Import-Csv -Delimiter "," -Path "C:\ADuser.csv"
  11. #Get Domain Base
  12. $searchbase = Get-ADDomain | ForEach { $_.DistinguishedName }
  13.  
  14. #Loop through all items in the CSV
  15. ForEach ($user In $csv)
  16. {
  17.  
  18. ## change your OU with your own OU
  19. $OU = "OU=New Users,OU=Users,OU=employee,DC=Contoso,DC=com"
  20. $Password = "Abc123+"
  21. $title= $user.'New Post title'
  22. $lastname= ($user.'Last name'.Substring(0,1).toupper() + $User.'Last name'.Substring(1).tolower())
  23. $Detailedname = $User.'First name' + " " + $lastname
  24. $UserFirstname = $User.'First name'
  25. $SAM = $User.'First name' + "." + $lastname
  26. $UPN= $UserFirstname + "." + $lastname + "@contoso.com"
  27. $ID= $user.ID
  28. $Displayname= "$Detailedname" + " " + "-" + " " + "$title"
  29. $Company= "Contoso"
  30. $Dis= "Contoso User"
  31. $group= "All Users","All Contoso Users"
  32. $homedrive= "\\nas1\home\%username%"
  33.  
  34.  
  35. #Check if the User exists
  36. $NameID = $user.ID
  37. $User = Get-ADUser -LDAPFilter "(EmployeeID=$NameID)"
  38. If ($User -eq $Null)
  39.  
  40. {
  41. #Create the User if it doesn't exist
  42.  
  43.  
  44. $create = New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $UPN -DisplayName $Displayname -GivenName $UserFirstname -Surname $lastname -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU -EmployeeID $ID -Title $title -Description $Dis -Company $Company -HomeDrive Z: -HomeDirectory $homedrive -ChangePasswordAtLogon $true
  45.  
  46. ## Adding User to Group
  47. Add-ADPrincipalGroupMembership -Identity $SAM -MemberOf $group
  48.  
  49. ## Creating Mailbox on EX2010
  50. Enable-Mailbox -Identity $SAM -Alias $SAM
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement