Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##***FUNCTIONS***##
- ##Create The mailbox
- Function Setup-Mailbox{
- Clear-Host
- if($global:company -eq "***"){
- $cuser = $global:firstname + ' ' + $global:lastname
- Write-Host "The current Selected OU is $global:ou"
- Read-Host -Prompt "Hit enter if this is correct. Otherwise close and start over"
- New-Mailbox `
- -Name $cuser `
- -Alias $global:calias `
- -UserPrincipalName $global:userprinciplename `
- -SamAccountName $global:samaccountname `
- -FirstName $global:firstname `
- -LastName $global:lastname `
- -Password $global:Password `
- -ResetPasswordOnNextLogon $global:false `
- -Database $global:database `
- -OrganizationalUnit $global:ou
- }
- elseif($global:company -eq "***"){
- $cuser = $global:firstname + ' ' + $global:lastname
- Write-Host "The current Selected OU is $global:ou"
- Read-Host -Prompt "Hit enter if this is correct. Otherwise close and start over"
- New-Mailbox `
- -Name $cuser `
- -Alias $global:calias `
- -UserPrincipalName $global:userprinciplename `
- -SamAccountName $global:samaccountname `
- -FirstName $global:firstname `
- -LastName $global:lastname `
- -Password $global:Password `
- -ResetPasswordOnNextLogon $global:false `
- -Database $global:database `
- -OrganizationalUnit $global:ou
- }
- }
- ##Select the database to store the mailbox. This will switch between the two for multiple users
- Function Select-Database{
- if ($global:lastdb -eq 1){$global:database = '****\First Storage Group\Mailbox Database'
- $global:lastdb = 0
- }
- elseif($global:lastdb -eq 0){$global:database = '****\Second Storage Group\Mailbox Database'
- $global:lastdb = 1
- }
- }
- ##Get the info needed to make a new user
- Function Get-UserInfo{
- $global:firstname = Read-Host -Prompt "Enter Users First Name: "
- $global:lastname = Read-Host -Prompt "Enter Users Last Name: "
- $global:samaccountname = $global:firstname.ToLower() + $global:lastname.Substring(0,1).ToLower()
- $global:calias = $global:firstname.ToLower() + "." + $global:lastname.ToLower()
- $global:caliasativ = $global:firstname.Substring(0,1).ToLower() + $global:lastname.ToLower()
- $global:userprinciplename = $global:samaccountname + '@***'
- $global:company = Read-Host -Prompt "Company Name: "
- $global:location = Read-Host -Prompt "Omaha, Florida, Boston, or Remote: "
- $global:office = $global:location
- $global:department = Read-Host -Prompt "Enter Users Department: "
- $global:title = Read-Host -Prompt "Enter Users Title: "
- $global:manager = Read-Host -Prompt "Enter Users Manager: "
- if($global:company -eq "***"){
- $phonel4 = Read-Host -Prompt "Enter last 4 phone digits: "
- $global:phone = "402-778-" + $phonel4
- }
- elseif($global:company -eq "****"){
- $phonel4 = Read-Host -Prompt "Enter 4 digit Jive extension: "
- $global:phone = "(508) 655-0342 x" + $phonel4
- }
- Clear-Host
- Write-Host "First Name: " $global:firstname
- Write-Host "Last Name: " $global:lastname
- Write-Host "Login Name: " $global:samaccountname
- Write-Host "Principle Name: " $global:userprinciplename
- Write-Host "Location: " $global:location
- Write-Host "Office: " $global:office
- Write-Host "Title: " $global:title
- Write-Host "Department: " $global:department
- Write-Host "Company: " $global:company
- Write-Host "Manager: " $global:manager
- Write-Host "Phone: " $global:phone
- if ($global:company -eq "***"){Write-Host "Email: " "$global:calias@***.com"}
- elseif ($global:company -eq "***"){Write-Host "Email: " "$global:caliasativ@***.com"}
- Read-Host -Prompt "If this info is correct hit enter. Otherwise close and startover"
- }
- ##Finish setting up the AD Account
- Function Finish-Account{
- #Finish Account Settings
- if ($global:company -eq "***"){$global:description = $global:title}
- elseif ($global:company -eq "****"){$global:description = $global:company + " " + $global:location + " | " + $global:department.TrimStart("**** -") + " | " + $global:title}
- Set-ADUser `
- -Identity $global:samaccountname `
- -Office $global:office `
- -Title $global:title `
- -Description $global:description `
- -Department $global:department `
- -Company $global:company `
- -Manager $global:manager `
- -OfficePhone $global:phone `
- # Protect from accdential delete
- Get-ADUser $global:samaccountname | Set-ADObject -ProtectedFromAccidentalDeletion $true
- # Rename account to match naming policy.
- if($global:company -eq "***"){
- Set Mailbox settings
- Set-CASMailbox $global:calias -ActiveSyncEnabled $false -OWAEnabled $false -PopEnabled $false -ImapEnabled $false
- #fix email addresses
- Set-Mailbox $global:calias -Alias $global:samaccountname -EmailAddressPolicyEnabled $false -EmailAddresses SMTP:$global:calias@americantitleinc.com,smtp:$global:samaccountname@americantitleinc.com
- }
- elseif($global:company -eq "***"){
- Set-CASMailbox $global:calias -ActiveSyncEnabled $false -OWAEnabled $false -PopEnabled $false -ImapEnabled $false
- #fix email addresses
- Set-Mailbox $global:calias -Alias $global:samaccountname -EmailAddressPolicyEnabled $false -EmailAddresses SMTP:$global:caliasativ@***.com,smtp:$global:samaccountname@***.com
- }
- }
- ##Function to run the account setup again
- Function RunAgain{
- $title = "Run Again?"
- $message = "Do you want to create another account?"
- $message
- $choice1 = New-Object System.Management.Automation.Host.ChoiceDescription 'Yes', "Create another user"
- $choice2 = New-Object System.Management.Automation.Host.ChoiceDescription 'No', "end script"
- $options = [System.Management.Automation.Host.ChoiceDescription[]]($choice1, $choice2)
- $result = $host.ui.PromptForChoice($title, $message, $options, 0)
- switch ($result)
- {
- 0 {
- Get-UserInfo
- Write-Host "Gathered Info"
- #Verify-Info
- ##Check if Name exists and if so ask for new name
- if(Check-ADAccount = $true){
- $global:samaccountname = Read-Host -Prompt "$global:samaccountname Is already taken. Please Select a new login name: "
- $global:userprinciplename = $global:samaccountname + '@***'
- }
- Write-Host "Verified accountname"
- Select-Database
- Write-Host "Selected Database " + $global:database
- Get-OU
- Write-Host "Set OU to " + $global:ou
- Setup-Mailbox
- Write-Host "Setup Mailbox"
- Start-Sleep -s 15
- Finish-Account
- Write-Host "Finished Account"
- RunAgain
- }
- 1 {
- exit
- }
- }
- }
- <#
- Function Verify-Info{
- Compile-Table
- $title = "Verify"
- $message = "Is the above Info Correct?"
- $message
- $choice1 = New-Object System.Management.Automation.Host.ChoiceDescription 'Yes', "Confirm User"
- $choice2 = New-Object System.Management.Automation.Host.ChoiceDescription 'No', "Start over"
- $options = [System.Management.Automation.Host.ChoiceDescription[]]($choice1, $choice2)
- $result = $host.ui.PromptForChoice($title, $message, $options, 0)
- switch ($result)
- {
- 0 {
- ##Do nothing to continue script
- }
- 1 {
- ##ReRun Script
- RunAgain
- }
- }
- }
- #>
- ##Function to check if account name already exists and to prompt for new name if exists
- Function Check-ADAccount($exists){
- $Usercheck = Get-ADUser -LDAPFilter "(sAMAccountName=$global:samaccountname)"
- If ($Usercheck -eq $Null) {$exists = $false}
- Else {$exists = $true}
- $exists
- return
- }
- ##Global Variables
- $global:caliasativ = ""
- $global:ou = ""
- $global:location = ""
- $global:caliasati = ""
- $global:firstname = ""
- $global:lastname = ""
- $global:samaccountname = ""
- $global:userprinciplename = ""
- $global:office = ""
- $global:title = ""
- $global:description
- $global:department = ""
- $global:company = ""
- $global:manager = ""
- $global:phone = ""
- $global:lastdb = 0
- $global:database = ""
- $global:password = ConvertTo-SecureString -String "****" -AsPlainText -Force
- ##import needed modules
- Import-Module ActiveDirectory
- add-pssnapin microsoft.exchange.management.powershell.admin #Exchange 2007
- #Add-PSSnapin microsoft.exchange.management.powershell.snapin #Exchange 2013
- ##Start Process
- Get-UserInfo
- Write-Host "Gathered Info"
- #Verify-Info
- ##Check if Name exists and if so ask for new name
- if(Check-ADAccount = $true){
- $global:samaccountname = Read-Host -Prompt "$global:samaccountname Is already taken. Please Select a new login name: "
- $global:userprinciplename = $global:samaccountname + '@***'
- }
- Write-Host "Verified accountname"
- Select-Database
- Write-Host "Selected Database $global:database"
- Get-OU
- Write-Host "Set OU to $global:ou"
- Setup-Mailbox
- Write-Host "Setup Mailbox"
- Start-Sleep -s 15
- Finish-Account
- Write-Host "Finished Account"
- RunAgain
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement