Advertisement
Guest User

UserSetupScriptGeneric.ps1

a guest
Jul 11th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Created by Randy Wintle MVP, Communications Server
  2. #Basic Script to Enable user accounts for AD,Exchange 2010, Unified Messaging and Lync Server 2010
  3.  
  4. #This script will create a new AD user, enable their mailbox, enable their online archive, enable for UM and enable for Lync.
  5.  
  6. #This script has a lot of pauses in it, I was running into issues when running the commands too quickly, the pause may be reduced, but this worked for my environment.
  7.  
  8. #Define Environment Variables
  9.  
  10. $Lyncserver="Lync Pool"
  11. $exchangeserver="Exchange 2010 Server"
  12. $umpolicy="UM Mailbox Policy"
  13. $dialplan="Lync Voice Dial Plan"
  14. $voicepolicy="Lync Voice Policy"
  15. $locationpolicy="Lync Location Policy"
  16. $externalaccesspolicy="Lync External Access Policy"
  17. $userou="OU Where the user shoudl be created"
  18. $companyname="Your Company Name (Organization Tab in ADUC)"
  19. $mailboxdatabase="Your Mailbox Database"
  20. $archivedatabase="Your Database holding online archives"
  21. $retentionpolicy="Your retention policy"
  22. $sipdomain="your sip domain"
  23.  
  24. #Import Session information for Exchange and Lync Server
  25.  
  26. $usercredential= get-credential
  27. $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$exchangeserver/PowerShell/ -Authentication Kerberos -Credential $UserCredential
  28. Import-PsSession $exchangesession
  29. $lyncsession = new-pssession -connectionuri https://$Lyncserver/ocspowershell -credential $usercredential
  30. Import-PSSession $lyncsession
  31.  
  32. #Prompt for Username and Password
  33. $firstname = read-host -prompt "Enter First Name"
  34. $lastname = read-host -prompt "Enter Last Name"
  35. $username = read-host -prompt "Enter User Name (First Initial, Last Name  IE Jfallon)"
  36. $department = read-host -prompt "Enter Department: List Department Options"
  37. $title = read-host -prompt "Enter Job Title"
  38. $manager = read-host -prompt "Enter Manager in format of username IE jfallon"
  39. $Name=$Firstname+" "+$Lastname
  40. $accountpassword = read-host -assecurestring -prompt "Please Enter Temporary Password"
  41. #adjust how your UPN should look
  42. $upn = $username+ "@domain.com"
  43.  
  44. # You should adjust the $teluri field to customize how you want that teluri to be formatted. In my example, we have "2 digit extension", and our tel uri is the full DID below, you can adjust as neeeded
  45. #Prompt for extension and lync info
  46. $extension = read-host -prompt "Enter the extension"
  47. $teluri="tel:+120751896"+$extension
  48.  
  49. #create user and enable mailbox
  50.  
  51. New-Mailbox  -name $name -userprincipalname $upn -Alias $username -OrganizationalUnit $userou -SamAccountName $username -FirstName $FirstName -Initials '' -LastName $LastName -Password $accountpassword -ResetPasswordOnNextLogon $true -Database $mailboxdatabase -Archive -ArchiveDatabase $archivedatabase -RetentionPolicy $retentionpolicy
  52.  
  53. #pause for 30 seconds for AD
  54. write-host -foregroundcolor Green "Pausing for 30 seconds for AD Changes"
  55. Start-Sleep -s 30
  56.  
  57. #set user properties
  58.  
  59. Get-Mailbox $username | Set-User -Company $companyname -Department $department -title $title -Manager $manager
  60.  
  61. #Enable For Unified Messaging
  62.  
  63. Get-Mailbox $username | Enable-UMMailbox -ummailboxpolicy $umpolicy -sipresourceidentifier $upn -extensions $extension
  64.  
  65. #pause 10 for AD changes
  66.  
  67. write-host -foregroundcolor Green "Pausing 10 Seconds for AD Changes"
  68. Start-Sleep -s 10
  69.  
  70. #enable for lync and configure settings
  71.  
  72. Get-mailbox $username | Enable-csuser  -registrarpool $lyncserver -sipaddresstype EmailAddress -sipdomain $sipdomain
  73.  
  74. #pause 30 for Lync changes
  75.  
  76. write-host -foregroundcolor Green "Pausing 30 Seconds for Lync Changes"
  77. Start-Sleep -s 30
  78.  
  79. Get-mailbox $username | Set-CSUser -enterprisevoiceenabled $True -lineuri $teluri
  80.  
  81. Get-mailbox $username | Grant-CSVoicePolicy -policyname $voicepolicy
  82.  
  83. Get-mailbox $username | Grant-CSDialPlan -policyname $dialplan
  84.  
  85. Get-mailbox $username | Grant-CSLocationPolicy -policyname $locationpolicy
  86.  
  87. Get-mailbox $username | Grant-CSExternalAccessPolicy -policyname $externalaccesspolicy
  88.  
  89. #pause 30 Seconds and provide summary
  90.  
  91. write-host -foregroundcolor Green "Pausing 30 seconds for changes, then will provide a summary, if you do not wish to view the summary here you may close this window."
  92. Start-Sleep -s 30
  93.  
  94. write-host -foregroundcolor Green "Mailbox Summary"
  95. Get-Mailbox $username
  96.  
  97. write-host -foregroundcolor Green "Press any key to view UM and Lync Summaries ..."
  98.  
  99. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  100.  
  101. get-ummailbox $username
  102.  
  103. write-host -foregroundcolor Green "Press any key to view Lync Summary..."
  104.  
  105. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  106.  
  107. Get-CSUser $username
  108.  
  109. write-host -foregroundcolor Green "Press any key to exit"
  110. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  111.  
  112. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement