Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
  2.  
  3. set-location c:\quest
  4.  
  5. Add-Pssnapin quest.activeroles.admanagement
  6.  
  7. function any-key() {
  8.  
  9. #Press any key to continue
  10.  
  11. Write-Host "Press any Key to continue"
  12.  
  13. $x = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  14.  
  15. }
  16.  
  17.  
  18.  
  19. #Crappy error trapping, check if the user is faculty or staff, this is used later to
  20.  
  21. #determin which database to place the mailbox in
  22.  
  23. $Valid = 0
  24.  
  25. do{$FacStaff = Read-Host -Prompt "Is the User (F)aculty or (S)taff: "
  26.  
  27. if($FacStaff -eq "f"){
  28.  
  29. $FacStaff = "Faculty"
  30.  
  31. $FacStaffdb = "exchangedb.contoso.com\Faculty"
  32.  
  33. $Valid = 1}
  34.  
  35. elseif($FacStaff -eq "s"){
  36.  
  37. $FacStaff = "Staff"
  38.  
  39. $FacStaffdb = "exchangedb.contoso.com\Staff"
  40.  
  41. $Valid = 1}
  42.  
  43. else{$Valid = 0}}
  44.  
  45.  
  46.  
  47. until($valid -eq 1)
  48.  
  49.    
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. #Get variables to fill in account information
  58.  
  59. #For your script to be automated you will need to import the csv
  60.  
  61. #and Fill them in with $Firstname = $YourImportedCSV[0,1,2,3,etc].FirstName
  62.  
  63.  
  64.  
  65. $FirstName = Read-host -Prompt "Enter First Name: "
  66.  
  67. $LastName = Read-host -Prompt "Enter Last Name: "
  68.  
  69. $Account = Read-Host -Prompt "Enter Active Directory Name: "
  70.  
  71. $Initials = $Firstname.substring(0,1) + $Lastname.substring(0,1)
  72.  
  73. $TempPass = read-host -AsSecureString -Prompt "Enter Temporary Password"
  74.  
  75. $DisplayName = $FirstName+"  "+$LastName
  76.  
  77.  
  78.  
  79. #Append domain name to the end of account
  80.  
  81. $UPN=$Account+"@contoso.com"
  82.  
  83. #Set home directory information
  84.  
  85. $HomeDir='\\server\home\'+$Account
  86.  
  87. $HomeDrive='Z:'
  88.  
  89. $domain='@contoso.com'
  90.  
  91. #again with the crappy error trapping
  92.  
  93. $Valid = 0
  94.  
  95. Write-host "First Name = " $FirstName
  96.  
  97. write-host "LastName = " $Lastname
  98.  
  99. write-host "Active Directory Account =" $Account
  100.  
  101. do{$prompt = read-host -Prompt "Is This correct (Y/N): "
  102.  
  103. if($prompt -eq "y"){$Valid = 1}
  104.  
  105. elseif($prompt -eq "n"){exit 1}
  106.  
  107. else{$Valid = 0}}
  108.  
  109. until($Valid = 1)
  110.  
  111.  
  112.  
  113. #create the mailbox and fill it in with information collected so far
  114.  
  115. New-Mailbox -Name $DisplayName -Alias $Account -OrganizationalUnit 'contoso.com/Users' -UserPrincipalName $UPN -SamAccountName $Account -Firstname $FirstName -Initials $Initials -LastName $LastName -Password $TempPass -ResetPasswordOnNextLogon $false  -Database $FacStaffdb | set-mailbox -CustomAttribute1 $FacStaff
  116.  
  117. set-qaduser -Identity $DisplayName -homedirectory $HomeDir -HomeDrive $HomeDrive -displayName $DisplayName
  118.  
  119.  
  120.  
  121. #Create the home folder
  122.  
  123. $HomeFolderMasterDir='\\server\home\'
  124.  
  125. new-item -path $HomeFolderMasterDir -name $Account -type directory
  126.  
  127.  
  128.  
  129.  
  130.  
  131. #Puts \\server\home\%username% into a variable
  132.  
  133. $FolderName=$HomeFolderMasterDir+$Account
  134.  
  135. $DomainUser='contoso\'+$Account
  136.  
  137.  
  138.  
  139. #Set the NTFS permissions on the home folder
  140.  
  141. $ACL=get-acl $FolderName
  142.  
  143. $Ar = new-object system.security.accesscontrol.filesystemaccessrule($DomainUser, "FullControl","ContainerInherit, ObjectInherit", "None", "Allow")
  144.  
  145.    
  146.  
  147.                  
  148.  
  149. $ACL.AddAccessRule($Ar)
  150.  
  151.  
  152.  
  153. Set-Acl -aclobject $ACL -path $FolderName
  154.  
  155. any-key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement