Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
- set-location c:\quest
- Add-Pssnapin quest.activeroles.admanagement
- function any-key() {
- #Press any key to continue
- Write-Host "Press any Key to continue"
- $x = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
- }
- #Crappy error trapping, check if the user is faculty or staff, this is used later to
- #determin which database to place the mailbox in
- $Valid = 0
- do{$FacStaff = Read-Host -Prompt "Is the User (F)aculty or (S)taff: "
- if($FacStaff -eq "f"){
- $FacStaff = "Faculty"
- $FacStaffdb = "exchangedb.contoso.com\Faculty"
- $Valid = 1}
- elseif($FacStaff -eq "s"){
- $FacStaff = "Staff"
- $FacStaffdb = "exchangedb.contoso.com\Staff"
- $Valid = 1}
- else{$Valid = 0}}
- until($valid -eq 1)
- #Get variables to fill in account information
- #For your script to be automated you will need to import the csv
- #and Fill them in with $Firstname = $YourImportedCSV[0,1,2,3,etc].FirstName
- $FirstName = Read-host -Prompt "Enter First Name: "
- $LastName = Read-host -Prompt "Enter Last Name: "
- $Account = Read-Host -Prompt "Enter Active Directory Name: "
- $Initials = $Firstname.substring(0,1) + $Lastname.substring(0,1)
- $TempPass = read-host -AsSecureString -Prompt "Enter Temporary Password"
- $DisplayName = $FirstName+" "+$LastName
- #Append domain name to the end of account
- $UPN=$Account+"@contoso.com"
- #Set home directory information
- $HomeDir='\\server\home\'+$Account
- $HomeDrive='Z:'
- $domain='@contoso.com'
- #again with the crappy error trapping
- $Valid = 0
- Write-host "First Name = " $FirstName
- write-host "LastName = " $Lastname
- write-host "Active Directory Account =" $Account
- do{$prompt = read-host -Prompt "Is This correct (Y/N): "
- if($prompt -eq "y"){$Valid = 1}
- elseif($prompt -eq "n"){exit 1}
- else{$Valid = 0}}
- until($Valid = 1)
- #create the mailbox and fill it in with information collected so far
- 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
- set-qaduser -Identity $DisplayName -homedirectory $HomeDir -HomeDrive $HomeDrive -displayName $DisplayName
- #Create the home folder
- $HomeFolderMasterDir='\\server\home\'
- new-item -path $HomeFolderMasterDir -name $Account -type directory
- #Puts \\server\home\%username% into a variable
- $FolderName=$HomeFolderMasterDir+$Account
- $DomainUser='contoso\'+$Account
- #Set the NTFS permissions on the home folder
- $ACL=get-acl $FolderName
- $Ar = new-object system.security.accesscontrol.filesystemaccessrule($DomainUser, "FullControl","ContainerInherit, ObjectInherit", "None", "Allow")
- $ACL.AddAccessRule($Ar)
- Set-Acl -aclobject $ACL -path $FolderName
- any-key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement