<# .SYNOPSIS Helps to perform a base configuration of an Exchange 2013 lab environment. .DESCRIPTION Assist in setting up a lab environment, from creating mailboxes and users to setting up DL's .NOTES Version Change Log : 1.5 : 1.5 - More Advanced features added: Mobile Device Policy configuration OWA Mailbox Policiy configuration OWA Virtual Directory Configuration OWA Permission changes Custom Apps For Outlook Wish list : More complicated Mailboxes - Phone #'s, locations and addresses, department, company name : Mobile Device Quarantines : Complete lab setup - including Exchange prereq, install, reboots, etc. : Transport rule creation : More advanced password : Create room mailboxes based off of location, addresses, and make room lists based off this information : Assign permissions to shared mailboxes and allow customizable amount of shared mailboxes Rights Required : Local admin on server Sched Task Req'd : No Exchange Version : 2013 Author : Just A UC Guy [JAUCG] Email/Blog/Twitter : ( ) http://justaucguy.wordpress.com/ Dedicated Blog : http://justaucguy.wordpress.com/ Disclaimer : You are on your own. This was not written by, support by, or endorsed by Microsoft. Info Stolen from : http://mikepfeiffer.net/2013/04/how-toadd-a-custom-holiday-to-an-exchange-calendar-with-powershell-and-the-ewsmanaged-api/ : http://blogs.msdn.com/b/dhruvkh/archive/2012/04/06/working-with-tasksusing-exchange-web-services.aspx : http://gsexdev.blogspot.com/2012/02/ewsmanaged-api-and-powershell-how-to_22.html .LINK [TBD] .EXAMPLE .\Set-LabSetup-1.0.ps1 .INPUTS None. You cannot pipe objects to this script. #> #Requires -Version 2.0 param( [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false, Mandatory=$false)] [string] $strFilenameTranscript = $MyInvocation.MyCommand.Name + " " + (hostname)+ " {0:yyyy-MM-dd hh-mmtt}.log" -f (Get-Date), [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$true, Mandatory=$false)] [string] $TargetFolder = "c:\Install", # [string] $TargetFolder = $Env:Temp [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false, Mandatory=$false)] [bool] $WasInstalled = $false, [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false, Mandatory=$false)] [bool] $RebootRequired = $false, [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false, Mandatory=$false)] [string] $opt = "None", [parameter(ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false, Mandatory=$false)] [bool] $HasInternetAccess = ([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet) ) Start-Transcript -path .\$strFilenameTranscript | Out-Null $error.clear() Clear-Host Pushd # determine if BitsTransfer is already installed if ((Get-Module BitsTransfer).installed -eq $true){ [bool] $WasInstalled = $true }else{ [bool] $WasInstalled = $false } [string] $menu = @' ****************************************************************** Exchange Server 2013 Lab Setup for Testing ****************************************************************** Please select an option from the list below. 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) Create databases and replicas Create Mailboxes Create Distribution Groups Create Shared Mailboxes Create Rooms Populate email Populate calendars Populate Tasks DLP Policy Creation Create retention Policies 11) 12) 13) 14) 15) 16) 17) 18) 19) 20) 21) 22) 23) 24) 25) 26) 27) Configure quotas Configure Disclaimer(s) Transport Rule Creation Server Settings - OA, Evt Log, Msg Tracking Mobile Devices Policies OWA Policies Enabling Archives Configure Apps Configure Journaling Configure Delegation Configure Archive Quotas Create Dynamic Distribution Groups Configure custom Exchange URLs (OWA, OAB, etc) Modify Mobile Device Mailbox Policy Change OWA Virtual Directory Settings Change OWA Authentication Change existing OWA Mailbox Policies 50) Grant impersonation rights 97) Lab cleanup - remove mailboxes, etc. 98) All of the above 99) Exit Select an option.. [1-99]? '@ # Database Creation function create-database { # Create Databases $srvcount = (get-mailboxserver).count $dbcount = (get-mailboxdatabase).count write-host "Currently there are $srvcount Mailbox Servers with $dbcount databases." # New databases will be put on the first server and replicas on other servers $newdb = read-host "How many more databases do you want to create?" $dbloc = read-host "What directory do you want to use for mailbox database files(i.e. d:\exchange\databases)" if ((test-path $dbloc) -eq $false) { write-host "" write-host "Creating file location for database files." foregroundcolor green mkdir $dbloc write-host "" } $logloc = read-host "What directory do you want to use for mailbox database logs (i.e. d:\exchange\logs)" if ((test-path $logloc) -eq $false) { write-host "" write-host "Creating file location for log files." foregroundcolor green mkdir $logloc write-host "" } $n = 1 while (($n-1) -lt $newdb) { $dbname = "database"+$n $edbname = $dbname+".edb" $edbfilepath = $dbloc+"\"+$edbname $logpath = $logloc+"\"+$dbname $server1 = (get-mailboxserver).name $server = $server1[0] if ((get-mailboxdatabase $dbname -erroraction silentlycontinue) -eq $null) { new-mailboxdatabase -name $dbname -edbfilepath $edbfilepath -logfolderpath $logpath -server $server } else { $dbname = "database"+$n+"a" $edbname = $dbname+".edb" $edbfilepath = $dbloc+"\"+$edbname $logpath = $logloc+"\"+$dbname new-mailboxdatabase -name $dbname -edbfilepath $dbloc+"\"+$edbname -logfolderpath $logpath -server $server } $n++ } } # End database and replica creation # Validate DAG existence function dag-check { $DAGExistence = get-databaseavailabilitygroup if ($DAGExistence -ne $null) { # Create replicas $n = 1 $databases = get-mailboxdatabase foreach ($line in $database) { $mailserver = get-mailboxserver while ($n -lt $srvcount) { $ap = $n+1 $n2 = $n-1 $server = $mailserver[$n2] add-mailboxdatabasecopy -identity $line.name activationpreference $ap -server $server } } } else { CLS write-host "No Database Availability Group (DAG) exists so no replicas will be created." -foregroundcolor red } cls write-host "Database creation step complete." -foregroundcolor green write-host " " } # End DAG existence check # Create mailboxes function create-mailboxes { # mailboxes will be created in all available databases $track = 0 $database = (get-mailboxdatabase).name $password = read-host "Enter password" -AsSecureString $dbcount = (get-mailboxdatabase).count $domain = read-host "Enter a domain to be used for SMTP routing" $source = import-csv c:\temp\names.csv foreach ($line in $source) { $first = $line.first $last = $line.last $upn = $first+"."+$last+"@"+$domain $alias =$first+"."+$last $displayname = $line.first+" "+$line.last if ((get-mailbox $upn -erroraction silentlycontinue) -eq $null) { new-mailbox -userprincipalname $upn -alias $alias -database $database[$track] -displayname $displayname -Firstname $first -lastname $last -name $alias -password $password $track++ if ($track -ge $dbcount) { $track = 0 } } else { write-host "There is already a mailbox with the UPN of " nonewline write-host $upn -foregroundcolor red } } cls write-host "Mailbox step complete." -foregroundcolor green write-host " " } # End of the create-mailboxes function # Create Distribution Groups function create-distributiongroups { $dlcount = read-host "How many distribution groups would you like to create" $members = read-host "Do you want to populate the distribution groups with random members [y or n]" if ($members -eq "n") {write-host "OK. Blank Distribution groups will be created." } else { write-host "OK. Will populate distribution groups with 1 to 10 members." } $alias1 = "DistributionGroup" $displayname1 = "Distribution Group " $dlcounter = 1 while ($dlcounter -lt $dlcount) { $displayname = $displayname1+$dlcounter $alias = $alias1+$dlcounter new-distributiongroup -name $displayname -displayname $displayname -alias $alias -type distribution $dlcounter++ if ($members -eq "y") { $mailboxes = get-mailbox $NumOfMembers = get-random -minimum 1 -maximum 10 while ($NumOfMembers -lt 10) { $usercount = (get-mailbox).count $usernum = get-random -minimum 0 -maximum $usercount $member = $mailboxes[$usernum] add-distributiongroupmember -identity $alias -member $member -erroraction silentlycontinue $numofmembers++ } } } cls write-host "Distribution Groups step complete." -foregroundcolor green write-host " " } # End of the create-distributiongroups function # Create Distribution Groups function create-dynamicdistributiongroups { $random = read-host "Create random [1] Dynamic Distribution Groups or [2] create with a CSV file? [1 or 2]" if ($random -eq 1) { $dlcount = read-host "How many distribution groups would you like to create" $alias1 = "DistributionGroup" $displayname1 = "Distribution Group " $dlcounter = 1 while ($dlcounter -lt $dlcount) { $displayname = $displayname1+$dlcounter $alias = $alias1+$dlcounter $orgunit = read-host "Enter the OU for the Dynamic Distribution Group" new-dynamicdistributiongroup -name $displayname -displayname $displayname -alias $alias -RecipientFilter {RecipientType -eq 'UserMailbox'} -OrganizationalUnit $orgunit $dlcounter++ } } if ($random -eq 2) { $csvfile = read-host "Specify CSV file for creating Dynamic Distribution Groups" $csv = import-csv $csvfile foreach ($line in $csv) { new-dynamicdistributiongroup -name $line.displayname displayname $line.displayname -alias $line.alias -RecipientFilter {RecipientType -eq 'UserMailbox'} -OrganizationalUnit $line.orgunit } } write-host "Dynamic Distribution Groups step complete." foregroundcolor green write-host " " start-sleep 5 CLS } # End of the create-dynamicdistributiongroups function # Create Shared Mailboxes function create-sharedmailboxes { # mailboxes will be created in all available databases $track = 0 $database = (get-mailboxdatabase).name $password = read-host "Enter password" -AsSecureString $dbcount = (get-mailboxdatabase).count $domain = read-host "Enter a domain to be used for SMTP routing" $source2 = import-csv c:\temp\sharedmailboxes.csv foreach ($line in $source2) { $upn = $line.name+"@"+$domain $alias = $line.name new-mailbox -userprincipalname $upn -alias $alias -database $database[$track] -displayname $alias -name $alias -password $password shared $track++ if ($track -ge $dbcount) { $track = 0 } } cls write-host "Shared mailboxes step complete." -foregroundcolor green write-host " " } # end of the create-sharedmailboxes function # Create Rooms mailboxes function create-roommailboxes { # mailboxes will be created in all available databases $track = 0 $database = (get-mailboxdatabase).name $password = read-host "Enter password" -AsSecureString $dbcount = (get-mailboxdatabase).count $domain = read-host "Enter a domain to be used for SMTP routing" $source2 = import-csv c:\temp\roommailboxes.csv foreach ($line in $source2) { $upn = $line.name+"@"+$domain $alias = $line.name new-mailbox -userprincipalname $upn -alias $alias -database $database[$track] -displayname $alias -name $alias -password $password room $track++ if ($track -ge $dbcount) { $track = 0 } } cls write-host "Room mailboxes step complete." -foregroundcolor green write-host " " } # End of the create-sharedmailboxes function # Create Calendar Entries function new-calendarevent { [CmdletBinding(DefaultParametersetName='Identity')] param( [Parameter(Position=0, ParameterSetName='Identity')] $Identity, [Parameter(Position=1, Mandatory=$true)] $Subject, [Parameter(Position=2, Mandatory=$true)] $Date, [Parameter(Position=3)] [Switch]$Impersonate, [Parameter(Position=4)] $ExchangeVersion = 'Exchange2013_CU7', [Parameter(Position=5, ParameterSetName='Pipeline', ValueFromPipelineByPropertyName=$true)] $PrimarySmtpAddress, [Parameter(Position=6)] [System.Management.Automation.PSCredential] $Credential, [Parameter(Position=7)] $EWSUrl ) begin { #Load the EWS Assembly Add-Type -Path "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Microsoft.Exchange.WebServices.dll" } process { #Is the identity coming from the pipeline? if($PsCmdlet.ParameterSetName -eq 'Pipeline') { $Identity = $PrimarySmtpAddress.ToString() } #Create the ExchangeService object $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList ([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::$ExchangeVersion) #If Credential parameter used, set the credentials on the $service object if($Credential) { $service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList $Credential.UserName, $Credential.GetNetworkCredential().Password } #If EWSUrl parameter not used, locate the end-point using autoD if(!$EWSUrl) { $service.AutodiscoverUrl($Identity, {$true}) } else { $service.Url = New-Object System.Uri -ArgumentList $EWSUrl } #If Impersonation parameter used, impersonate the user if($Impersonate) { $ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId -ArgumentList ([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress),$Id entity $service.ImpersonatedUserId = $ImpersonatedUserId } #Configure the start and end time for this all day event $start = (get-date $date) $end = $start.addhours(24) #Create and save the appointment $appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $service $appointment.Subject = $Subject $appointment.Start = $Start $appointment.End = $End $appointment.IsAllDayEvent = $true $appointment.IsReminderSet = $false $appointment.Categories.Add('Holiday') $appointment.Location = 'United States' $appointment.LegacyFreeBusyStatus = [Microsoft.Exchange.WebServices.Data.LegacyFreeBusyStatus]::Free $appointment.Save([Microsoft.Exchange.WebServices.Data.SendInvitationsMod e]::SendToNone) } } # End of the new-calendarevent function # Create Task Entries function new-task { [CmdletBinding(DefaultParametersetName='Identity')] param( [Parameter(Position=0, ParameterSetName='Identity')] $Identity, [Parameter(Position=1, Mandatory=$true)] $subject, [Parameter(Position=2, Mandatory=$true)] $StartDate, [Parameter(Position=3, Mandatory=$true)] $EndDate, [Switch]$Impersonate, [Parameter(Position=4)] # UPDATED to Exchange 2013 $ExchangeVersion = 'Exchange2013_SP1', [Parameter(Position=5, ParameterSetName='Pipeline', ValueFromPipelineByPropertyName=$true)] $PrimarySmtpAddress, [Parameter(Position=6)] [System.Management.Automation.PSCredential] $Credential, [Parameter(Position=7)] $EWSUrl ) begin { #Load the EWS Assembly - UPDATED to Exchange 2013 Add-Type -Path "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Microsoft.Exchange.WebServices.dll" } process { #Is the identity coming from the pipeline? if($PsCmdlet.ParameterSetName -eq 'Pipeline') { $Identity = $PrimarySmtpAddress.ToString() } #Create the ExchangeService object $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList ([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::$ExchangeVersion) #If Credential parameter used, set the credentials on the $service object if($Credential) { $service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList $Credential.UserName, $Credential.GetNetworkCredential().Password } #If EWSUrl parameter not used, locate the end-point using autoD if(!$EWSUrl) { $service.AutodiscoverUrl($Identity, {$true}) } else { $service.Url = New-Object System.Uri -ArgumentList $EWSUrl } #If Impersonation parameter used, impersonate the user if($Impersonate) { $ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId -ArgumentList ([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress),$Id entity $service.ImpersonatedUserId = $ImpersonatedUserId } #Create and save the task $task = New-Object Microsoft.Exchange.WebServices.Data.Task ArgumentList $service $task.Subject = $subject $task.StartDate = $startdate $task.DueDate = $enddate $task.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Tas ks) # ([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Notes) } } # End of the new-task function # Import calendar events function Create-CalendarEvents { $events = import-csv c:\scripts\calendarevents.csv $import = read-host "Do you want to import calendar events into all mailboxes or random mailboxes ['a' or 'r']" if ($import -eq "a") { $mailboxes = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress foreach ($line in $mailboxes) { $primary = $line.local+"@"+$line.domain foreach ($line in $events) { # get-mailbox | new-calendarevent -subject $line.subject -date $line.date -impersonate new-calendarevent -identity $primary -subject $line.subject -date $line.date -impersonate } write-host "Calendar entries for $line.displayname have been added." -foregroundcolor green } } else { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $counter = 0 $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress while ($counter -lt $range) { foreach ($line in $events) { $address = $mailbox[$counter] $primary = $address.local+"@"+$address.domain get-mailbox $primary | new-calendarevent -subject $line.subject -date $line.date -impersonate } $counter++ $name = (get-mailbox $primary).displayname write-host "Calendar entries for $name have been added." foregroundcolor green } } } # End Create Calendar Items Function # Import Tasks function Create-Tasks { $tasks = import-csv c:\scripts\tasks.csv $import = read-host "Do you want to import calendar events into all mailboxes or random mailboxes ['a' or 'r']" if ($import -eq "a") { $mailboxes = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress foreach ($line in $mailboxes) { $primary = $line.local+"@"+$line.domain foreach ($line2 in $tasks) { # get-mailbox | new-task -subject $line.subject -date $line.date -impersonate new-task -identity $primary -subject $line2.subject startdate $line2.startdate -enddate $line2.enddate -impersonate } write-host "Task entries for $line.displayname have been added." -foregroundcolor green } } else { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $counter = 0 $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress while ($counter -lt $range) { foreach ($line in $tasks) { $address = $mailbox[$counter] $primary = $address.local+"@"+$address.domain get-mailbox $primary | new-task -subject $line.subject startdate $line.startdate -enddate $line.enddate -impersonate } write-host "Task entries for $primary have been added." foregroundcolor green $counter++ } } } # End Create Tasks Function # Impersonation Function function add-impersonation { $answer = read-host "Does your user account need the impersonation right before proceeding [y or n]" if ($answer -eq "y") { $user = [Environment]::UserName # Create Management Scope for impersonation if ((get-managementscope "impersonation") -eq $null) { New-ManagementScope –Name:Impersonation – RecipientRestrictionFilter {RecipientType -eq "UserMailbox"} } #Assign impersonation to a user New-ManagementRoleAssignment –Role:ApplicationImpersonation – User:$user –CustomRecipientWriteScope:Impersonation } else { $answer2 = read-host "Does another user account need the impersonation right before proceeding [y or n]" if ($answer2 -eq "y") { $user = read-host "Enter the name of the account that needs impersonation rights" # Create Management Scope for impersonation if ((get-managementscope "impersonation") -eq $null) { New-ManagementScope –Name:Impersonation – RecipientRestrictionFilter {RecipientType -eq "UserMailbox"} } #Assign impersonation to a user New-ManagementRoleAssignment –Role:ApplicationImpersonation –User:$user –CustomRecipientWriteScope:Impersonation } } } # End of add-impersonation # Quotas Function function configure-quotas { write-host "Enter your Quota values:" $iwq = read-host "Issue Warning Quota [in MB, unlimited]" if ([string]$iwq -ne "unlimited") { [string]$iwq = [string]$iwq+" MB" } [string]$psq = read-host "Prohibit Send Quota [in MB]" if ($psq -ne "unlimited") { [string]$psq = [string]$psq+" MB" } [string]$psrq = read-host "Prohibit Send/Receive Quota [in MB]" if ([string]$psrq -ne "unlimited") { [string]$psrq = [string]$psrq+" MB" } $answer = read-host "Do you want to apply the policies to all users or random users [a or r]" if ($answer -eq "a") { $mailboxes = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress foreach ($line in $mailboxes) { $primary = $line.local+"@"+$line.domain set-mailbox $primary -ProhibitSendQuota $psq ProhibitSendReceiveQuota $psrq -IssueWarningQuota $iwq UseDatabaseQuotaDefaults $false write-host "The mailbox for $primary has had their quotas modified as requested:" -foregroundcolor green get-mailbox $primary | ft ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota, UseDatabaseQuotaDefaults } write-host "Quotas configured for all mailboxes as requested." } else { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $counter = 0 $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).primarysmtpaddress while ($counter -lt $range) { $address = $mailbox[$counter] $primary = $address.local+"@"+$address.domain set-mailbox $primary -ProhibitSendQuota $psq ProhibitSendReceiveQuota $psrq -IssueWarningQuota $iwq UseDatabaseQuotaDefaults $false write-host "The mailbox for $primary has had their quotas modified as requested:" -foregroundcolor green get-mailbox $primary | ft ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota, UseDatabaseQuotaDefaults $counter++ } write-host "Quotas configured for $range mailboxes as requested." } start-sleep 5 } # End of Quotas function # Check for Old Disclaimers function Check-OldDisclaimers { $rulecheck = (Get-TransportRule).ApplyHtmlDisclaimerText $rulecheck2 = get-transportrule | where {$_.ApplyHtmlDisclaimerText ne $null} if ($rulecheck -eq $null) { write-host " " write-host "There are no disclaimers in place now." foregroundcolor green write-host " " } else { foreach ($line in $rulecheck2) { write-host " " write-host "There is a transport rule in place called $line that is a disclaimer rule." -ForegroundColor Yellow write-host " " } } } #End of the Check-OldDisclaimers function # Add New Disclaimers function Configure-NewDisclaimers { $name = read-host "Name of the disclaimer rule" $DisclaimerNameCheck = get-transportrule | where {$_.name -eq $name} if ($DisclaimerNameCheck -eq $null) { $text = read-host "Disclaimer text or HTML" New-TransportRule -FromScope 'NotInOrganization' ApplyHtmlDisclaimerLocation 'Append' -ApplyHtmlDisclaimerText $text ApplyHtmlDisclaimerFallbackAction 'Wrap' -Name $name StopRuleProcessing:$false -Mode 'Enforce' -Comments ' ' -RuleErrorAction 'Ignore' -SenderAddressLocation 'Header' } else { write-host "There is a rule with the same name." -nonewline write-host " Please try the option again." -ForegroundColor Red write-host " " Configure-NewDisclaimers } } # End of the Configure-NewDisclaimers function # Enable Archives for all or some users function enable-archives { $selection = read-host "Do you want to enable archives for all mailboxes or random mailboxes [a or r]" $location = read-host "Would you like to create a new mailbox database for the archive mailboxes [y or n]" if ($location -eq "n") { $database = read-host "Which database will the archive mailboxes be placed in" } if ($location -eq "y") { $srv = ($server[0]).name write-host "The new archive database will bew placed on $srv." $directory1 = read-host "Please enter a valid directory to place the database files" $directory2 = read-host "Please enter a valid directory to place the log files" $archivename = "ArchiveDatabase" $edb = $directory1+"\"+$archivename+".edb" $log = $directory2+"\"+$archivename $server = get-mailboxserver new-mailboxdatabase -name $archivename -edbfilepath $edb logfolderpath $log -server $srv -erroraction silentlycontinue } # Enable the mailboxes to have archive mailboxes if ($selection -eq "a") { $mailboxes = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).alias foreach ($line in $mailboxes) { enable-mailbox $line -Archive -ArchiveDatabase $database erroraction silentlycontinue } $name = (get-mailbox $alias).displayname write-host "An archive mailbox for $name has been created." foregroundcolor green } else { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $counter = 0 $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).alias while ($counter -lt $range) { $alias = $mailbox[$counter] enable-mailbox $alias -Archive -ArchiveDatabase $database -erroraction silentlycontinue $counter++ } $name = (get-mailbox $alias).displayname write-host "All archive mailboxes have been created." foregroundcolor green } } # End function for archive mailboxes # Configuring apps forExchange 2013 function configure-Apps { $option = read-host "Do you want to configure Apps (1) or add new Apps (2)" # Prep Random mailboxes (version 1) $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).alias # Create Random User List $counter = 0 $userlist = @() while ($counter -lt $range) { $alias = $mailbox[$counter] $userlist += @($alias) $counter++ } if ($option -eq "1") { write-host "Currently there are these apps installed in your Exchange Server 2013 environment" get-app -OrganizationApp |ft displayname,providedto,userlist auto $app = (get-app -OrganizationApp).appid $choice = read-host "Do you want to limit the apps to random users or allow them for all users [r or a]" $mailboxes = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).alias if ($choice -eq "a") { $name = (get-mailbox $alias).displayname foreach ($line in $mailboxes) { foreach ($line in $app) { set-app $line -OrganizationApp $true -enabled $true } } write-host "Apps have been configured for all users." foregroundcolor green } else { foreach ($line in $app) { Set-App $line -organizationapp -ProvidedTo SpecificUsers -UserList $userlist } } } else { $choice2 = read-host "Install apps from this script (1) or choose your own apps (2) " write-host " " $choice = read-host "Do you want to limit the apps to random users or allow them for all users [r or a]" if ($choice2 -eq 1) { write-host " " write-host "For your custom app, you need an XML Manifest file in order to install it." -ForegroundColor Green write-host " " # $xml = read-host "Enter a local path to the XML file for the App " $Data = get-content -Encoding byte -Path "c:\scripts\manifest.xml" -ReadCount 0 } else { $xml = read-host "What is the full path and file name for your XML file? [i.e. \scripts\manifest.xml] " $Data = get-content -Encoding byte -Path $xml -ReadCount 0 } if ($choice -eq "a") { new-app -DefaultStateForUser Enabled -filedata $data OrganizationApp } else { new-app -DefaultStateForUser Enabled -filedata $data OrganizationApp -ProvidedTo SpecificUsers -UserList $userlist } } } # end of the configure-Apps function # Create Retention Policies function create-retentionpolices { $createorapply = read-host "[1] Create or [2] Apply retention policies [1 or 2]" if ($createorapply -eq 1) { $polno = read-host "How many Retention Policies do you want to create" $polcounter = 0 while ($polcounter -lt $polno) { $currentpol = $polcounter +1 $polname = read-host "Specify a name for Rentention Policy number $currentpol" $tagno = read-host "How many Retention Tags do you want to create" $counter = 0 $alltags = @() $allpolicies = @() while ($counter -lt $tagno) { $current = $counter + 1 $name = read-host "Specify a name for Retention Tag number $current" $allpolicies += ,($name) $time = read-host "Specify a time frame to apply the tag (i.e. 60, 90, 120)" $RetentionAction = read-host "Specify a retention action (DeleteAndAllowRecovery, PermanentlyDelete, MoveToArchive)" if ($retentionaction -eq "MoveToArchive") { $type = "all" } else { $type = read-host "Specify which folders will be affect (All, Inbox, etc. )" } $comment = read-host "Specify a comment for the Retention Tag (optional)" $alltags += ,($name) if ($retentionaction -eq "permanentlyDelete") { $archive = $false } else { $archive = $true } New-RetentionPolicyTag -Name $name -Type $type RetentionAction $retentionaction -RetentionEnabled:$archive AgeLimitForRetention $time -Comment $comment $counter++ } new-retentionpolicy -name $polname -RetentionPolicyTagLinks $alltags $polcounter++ } $action = read-host "Do you want to apply these policies to your users now? [y or n]" } # After creating polcies - create them? if ($action -eq "y") {$createorapply = 2} if ($createorapply -eq 2) { $allpolicies = (get-retentionpolicy).name foreach ($line in $allpolicies) { $action2 = read-host "For the retention policy $line, do you want to apply this policy to any users? [y or n]" if ($action2 -eq "y") { $applyto = read-host "Do you want to apply the policies to [a] all users, [r] random users or [c] use a csv file? [a, r or c]" if ($applyto -eq "a") { get-mailbox | set-mailbox -retentionpolicy $line } if ($applyto -eq "r") { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $mailbox = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).alias $counter = 0 $userlist = @() while ($counter -lt $range) { $alias = $mailbox[$counter] get-mailbox $alias | set-mailbox -retentionpolicy $line $counter++ } } if ($applyto -eq "c") { # CSV format is just the mailbox alias, with a header of 'alias' $csv = read-host "Specify a CSV file to read from" foreach ($line in $csv) { get-mailbox $line.alias | set-mailbox retentionpolicy $line } } } } } } # End of the create-retentionpolices function. # Create new mobile device policies function create-mobiledevicepolicy { write-host " " write-host "For now, this function will " -nonewline write-host "only create the password policy portion" -nonewline ForegroundColor red write-host " of the Mobile Device Policy." write-host " " start-sleep 5 write-host "The existing Mobile Device Mailbox Policies are:" Get-MobileDeviceMailboxPolicy |ft id $name = read-host "What is the name of the new Mobile Device Mailbox Policy" $IsDefault = read-host "Will this policy be the default policy [y or n]" if ($isdefault -eq "y") { $isdefault = $true } else { $isdefault = $false } $password = read-host "Do you want to create a device password policy [y or n]" if ($password -eq "y") { $AlphanumericPasswordRequired = read-host "Will alphanumeric passwords be required [y or n]" if ($AlphanumericPasswordRequired -eq "y") { $AlphanumericPasswordRequired = $true }else { $AlphanumericPasswordRequired = $false } $PasswordRecoveryEnabled = read-host "Will password recovery be enabled [y or n]" if ($PasswordRecoveryEnabled -eq "y") { $PasswordRecoveryEnabled = $true }else { $PasswordRecoveryEnabled = $false } $MaxPasswordFailedAttempts = read-host "How many failed password attempts [4 through 16 or the value Unlimited]" $MinPasswordLength = read-host "What is the minimum password length [1 through 16 or the value $null]" $complex = read-host "Do you want a complex password policy [y or n]" $PasswordHistory = read-host "How many passwords for the device pasword history [1, 3, 7?]" if ($complex -eq "y") { $MinPasswordComplexCharacters = read-host "What will the minumim complex password characters be allowed [valid range is from 1 to 4]" New-MobileDeviceMailboxPolicy -name $name -MinPasswordLength $MinPasswordLength -MaxPasswordFailedAttempts $MaxPasswordFailedAttempts -PasswordEnabled $true -AlphanumericPasswordRequired $AlphanumericPasswordRequired -PasswordRecoveryEnabled $PasswordRecoveryEnabled -MinPasswordComplexCharacters $MinPasswordComplexCharacters -IsDefault $isdefault -PasswordHistory $PasswordHistory } else { New-MobileDeviceMailboxPolicy -name $name -MinPasswordLength $MinPasswordLength -MaxPasswordFailedAttempts $MaxPasswordFailedAttempts -PasswordEnabled $true -AlphanumericPasswordRequired $AlphanumericPasswordRequired -PasswordRecoveryEnabled $PasswordRecoveryEnabled -IsDefault $isdefault -PasswordHistory $PasswordHistory } } if ($password -eq "n") { New-MobileDeviceMailboxPolicy -name $name } } # End of the create-mobiledevicepolicy function # Create an OWA Policy function create-OWApolicy { write-host " " write-host "For now, this function will " -nonewline write-host "only create a basic version" -nonewline -ForegroundColor red write-host " of the OWA Mailbox Policy." write-host " " start-sleep 5 write-host "The existing OWA Mailbox Policies are:" Get-OWAMailboxPolicy |ft id $name = read-host "What is the name of the new OWA Mailbox Policy" $IsDefault = read-host "Will this policy be the default policy [y or n]" if ($isdefault -eq "y") {$isdefault = $true} else {$isdefault = $false} $AllowOfflineOn = read-host "Do you want to enable OWA offline in this policy [PrivateComputersOnly | NoComputers | AllComputers]" $ChangePasswordEnabled = read-host "Would you like their password change opion to appear [y or n]" if ($ChangePasswordEnabled -eq "y") {$ChangePasswordEnabled = $true} else {$ChangePasswordEnabled = $false} $JunkEmailEnabled = read-host "Enable Junk mail in OWA [y or n]" if ($JunkEmailEnabled -eq "y") {$JunkEmailEnabled = $true} else {$JunkEmailEnabled = $false} $LinkedInEnabled = read-host "Would you like to enable LinkedIn for OWA [y or n]" if ($LinkedInEnabled -eq "y") {$LinkedInEnabled = $true} else {$LinkedInEnabled = $false} $PublicFoldersEnable = read-host "Enable Public folders in OWA [y or n]" if ($PublicFoldersEnable -eq "y") {$PublicFoldersEnable = $true} else {$PublicFoldersEnable = $false} $RulesEnabled = read-host "Enable Rules in OWA [y or n]" if ($RulesEnabled -eq "y") {$RulesEnabled = $true} else {$RulesEnabled = $false} write-host " " write-host "Creating your policy now." -ForegroundColor green write-host " " if ($isdefault -eq $true) { new-OwaMailboxPolicy -name $name set-OwaMailboxPolicy -isdefault $isdefault -identity $name AllowOfflineOn $AllowOfflineOn -ChangePasswordEnabled $ChangePasswordEnabled -JunkEmailEnabled $JunkEmailEnabled PublicFoldersEnable $PublicFoldersEnable -RulesEnabled $RulesEnabled } else { new-OwaMailboxPolicy -name $name set-OwaMailboxPolicy -identity $name -AllowOfflineOn $AllowOfflineOn -ChangePasswordEnabled $ChangePasswordEnabled JunkEmailEnabled $JunkEmailEnabled -PublicFoldersEnable $PublicFoldersEnable -RulesEnabled $RulesEnabled } } # End of the create-OWApolicy function # Create new Room Lists Function New-RoomList { write-host " " Write-host "This function will help you create rooms and room lists for your test environment, assuming" -ForegroundColor green write-host "the OU's and rooms are not created so far." ForegroundColor green write-host " " $answer1 = read-host "Create room lists from scratch? [y or n]" If ($answer1 -eq "y") { $csvmanual = read-host "Do you want to [1] use a CSV file or [2] enter the rooms manually ? [1 or 2]" If ($csvmanual -eq 1) { # import rooms and room lists from CSV file # CSV format: # roomlist,room,ou $csvfile = read-host "Specify a CSV file to read from" $csv = Import-csv $csvfile write-host "No column validation here - use this at your own risk." # pausing Write-Host "Press any key to continue ..." $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") Foreach ($line in $csv) { # Check for the existence of the Room list, create if it does not exist if ((get-distributiongroup $line.roomlist) -eq $null) { New-DistributionGroup -Name $line.roomlist OrganizationalUnit $line.ou -RoomList } $track = 0 $database = (get-mailboxdatabase).name write-host "For the new Room Mailbox:" $mbx = $line.room $password = read-host "Enter password for the $mbx mailbox" -AsSecureString $dbcount = (get-mailboxdatabase).count $domain = read-host "Enter a domain to be used for the rooms SMTP address" # $source2 = import-csv c:\temp\roommailboxes.csv $name = $line.room $name = $name -replace '\s','' $upn = $name+"@"+$domain new-mailbox -userprincipalname $upn -alias $name database $database[$track] -displayname $line.room -name $name -password $password -room $track++ if ($track -ge $dbcount) { $track = 0 } } # Add members according to the CSV file provided Add-DistributionGroupMember -Identity $line.roomlist -Member $line.room } If ($csvmanual -eq 2) { $norooms = read-host "How many rooms do you want to create?" $noroomlists = read-host "How many room lists do you want to create?" $counter = 0 while ($counter -lt $norooms) { $roomname = read-host "Enter a name for the room" $capacity = read-host "Enter a room capacity" $ou = read-host "Enter an OU to search for [i.e. rooms]" Get-OrganizationalUnit -SearchText $ou |ft *canonicalname* $ou = read-host "Copy one of the OUs above to use for placing the room mailboxes or enter a new one" New-mailbox -Name $roomname -OrganizationalUnit $ou -room -ResourceCapacity $capacity $counter++ } $counter = 0 while ($counter -lt $noroomlists) { $roomlist = read-host "Enter a name for the room list" $ou2 = read-host "Enter an OU for the room list" New-DistributionGroup -Name $roomlist -OrganizationalUnit $ou2 -RoomList $NoRoomMembers = read-host "How many rooms do you want to add to the $roomlist roomlist?" $counter2 = 0 while ($counter -lt $NoRoomMembers) { $RoomListMember = read-host "What room do you want to add to the $roomlist room list?" Add-DistributionGroupMember -Identity $roomlist Member $RoomListMember $counter2++ } $counter++ } } } If ($answer1 -eq "n") { write-host " " write-host "Exiting room list function...." -foregroundcolor red write-host " " start-sleep 5 cls } } # End of the New-RoomList function # Configure Journaling for Exchange function configure-journaling { $journaloption = read-host "Do you want to configure [1] Per User Journaling or [2] Journaling for all messages? [1 or 2]" # Scope options - Internal | External | Global $mailbox = read-host "Do you need to create a journal mailbox? [y or n]" $database = read-host "Do you need to create a journal database? [y or n]" $name = read-host "Provide a name for the journal rule" if ($database -eq "y") { write-host "The next part of the script will ask for how many databases to create. Choose 1." -foregroundcolor Green create-database } else { $dbname = read-host "What database would you like to use for journaling?" } if ($mailbox -eq "y") { $journalmailbox = read-host "What will you call the journaling mailbox?" $password = read-host "Enter a password" -AsSecureString $prefix = read-host "Enter a prefix for the User Principal Name [i.e. @domain.local]" $mailbox = $journalmailbox+$prefix write-host "The $journalmailbox will be created in the Users OU" new-mailbox -userprincipalname $mailbox -alias $journalmailbox database $tbd -displayname $journalmailbox -name $journalmailbox password $password } else { $journalmailbox = read-host "What is the name of the journaling mailbox?" } if ($journaloption -eq "1") { $nousers = read-host "How many users do you want to configure journaling for?" $counter = 0 $list = @() while ($counter -lt $nousers) { $user = read-host "What user do you want to configure for journaling? [user alias]" $email = (get-mailbox $user).primarysmtpaddress $smtp = $email.local+"@"+$email.domain $list += ,($smtp) $counter++ } # Configure journaling for the user New-JournalRule -Name $name -JournalEmailAddress $smtp -Scope Global -recipient $smtp -Enabled $true } else { # Configure journaling for the organization $email = (get-mailbox $journalmailbox).primarysmtpaddress $smtp = $email.local+"@"+$email.domain New-JournalRule -Name $name -JournalEmailAddress $smtp -Scope Global -Enabled $true } } # End the Configure Journaling function # Configure Delegation function Configure-delegation { $userA = read-host "What user needs delegation rights? [enter the user's alias]" $userB = read-host "What user mailbox will have access granted to it? [enter the user's alias]" $accessrights = read-host "What access rights will be granted? [use commas if more than one]" $folder = read-host "All folders or specific folder [a or s]" if ($folder -eq "a") { $folder2 = "*" $combo = $usera+":\"+$folder2 add-MailboxFolderPermission -Identity $userB -User $UserA AccessRights $accessrights } if ($folder -eq "s") { $folder2 = read-host "Which folder will the rights apply to" $combo = $usera+":\"+$folder2 # Add the folder tothe user's mailbox being modified" $name = $userB+":\"+$folder2 add-MailboxFolderPermission -Identity $name -User $UserA AccessRights $accessrights } } # End the Configure Delegation function # Configure Archive Quotas function Configure-ArchiveQuotas { # Added in version 1.3 write-host "Enter your Quota values:" $awq = read-host "Archive Warning Quota [in MB, unlimited]" if ([string]$awq -ne "unlimited") { [string]$awq = [string]$awq+" MB" } [string]$aq = read-host "Archive Quota [in MB]" if ($aq -ne "unlimited") { [string]$aq = [string]$aq+" MB" } $answer = read-host "Do you want to apply the archive quota policies to (a) all users, (r) random users or (c) use CSV files [a, r, c]" # Configure all mailbox archive quotas if ($answer -eq "a") { $mailboxes = (get-mailbox | where {($_.RecipientTypeDetails -ne "DiscoveryMailbox") -and ($_.archivestate -ne "none")}).primarysmtpaddress foreach ($line in $mailboxes) { $primary = $line.local+"@"+$line.domain set-mailbox $primary -ArchiveQuota $aq -ArchiveWarningQuota $awq write-host "The mailbox for $primary has had their archive quotas modified as requested:" -foregroundcolor green get-mailbox $primary | ft ArchiveQuota, ArchiveWarningQuota } write-host "Quotas configured for all mailboxes as requested." # Configure Random mailboxes } if ($answer -eq "r") { $mbxcount = (get-mailbox | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}).count $range = get-random -minimum 0 -maximum $mbxcount $counter = 0 $mailbox = (get-mailbox | where {($_.RecipientTypeDetails -ne "DiscoveryMailbox") -and ($_.archivestate -ne "none")}).primarysmtpaddress while ($counter -lt $range) { $address = $mailbox[$counter] $primary = $address.local+"@"+$address.domain set-mailbox $primary -ArchiveQuota $aq -ArchiveWarningQuota $awq write-host "The mailbox for $primary has had their archive quotas modified as requested:" -foregroundcolor green get-mailbox $primary | ft ArchiveQuota, ArchiveWarningQuota $counter++ } write-host "Quotas configured for $range mailboxes as requested." } # Configure mailbox archive quotas via CSV file if ($answer -eq "c") { $csvfile = read-host "Specify a CSV file (complete file path) with alias, archivequota and archivewarningquota values" $csv = import-csv $csvfile foreach ($line in $csv) { # Verify the account has an archive $test = (get-mailbox $line.alias).archivestate if ($test -ne "none") { set-mailbox $line.alias -ArchiveQuota $line.archivequota -ArchiveWarningQuota $line.archivewarningquota $display = (get-mailbox $line.alias).displayname write-host "The mailbox for $display has had their archive quotas modified as requested:" -foregroundcolor green } } } start-sleep 5 cls } # End the Configure Archive Quotas function Configure-URLs { $FQDN = Read-Host 'Enter the URL you want to use for your Exchange URLs.' $FQDN2 = read-host "Enter the URL you want to use for AutoDiscover [ie autodiscover.mail.com]" write-host $FQDN" will be used for the common name of all virtual directories." start-sleep -seconds 10 # To be used if setting all CAS the same $cas = get-clientaccessserver # To be used if setting only one CAS server up # $cas = Read-Host 'Enter the name of the CAS server you want to modify.' foreach ($line in $cas) { $casserver = $line.name write-host $casserver" will have it's URLs modified." } start-sleep -seconds 10 # Set various VD - ews, oab, autodiscover, ecp, autodiscover, outlook anywhere, write-host " " write-host "You picked "$FQDN" for the name in the environment." ForegroundColor green write-host "Your FQDNS will be as follows for internal and external URLs:" write-host " " write-host "https://$FQDN/exchange.asmx" write-host "https://$FQDN/owa" write-host "https://$FQDN/Microsoft-Server-ActiveSync" write-host "https://$FQDN/oab" # Skip if pre-2010 write-host "https://$FQDN/ecp" write-host " " write-host "Is this OK? Settings will apply in 5 seconds. Hit any key to abort." -ForegroundColor green write-host " " start-sleep 5 foreach ($line in $cas) { # EWS setting Set-WebServicesVirtualDirectory -Identity "$line\EWS (Default Web Site)" -internalurl https://$FQDN/ews/exchange.asmx -externalurl https://$FQDN/ews/exchange.asmx -confirm:$false # OWA setting set-OWAVirtualDirectory -Identity "$line\owa (Default Web Site)" -InternalURL https://$FQDN/owa -externalurl https://$FQDN/owa confirm:$false # ActiveSync setting Set-ActiveSyncVirtualDirectory -Identity "$line\Microsoft-ServerActiveSync (Default Web Site)" -InternalURL https://$FQDN/MicrosoftServer-ActiveSync -externalurl https://$FQDN/Microsoft-Server-ActiveSync -confirm:$false #OAB setting Set-OabVirtualDirectory -Identity "$line\OAB (Default Web Site)" -InternalURL https://$FQDN/oab -externalurl https://$FQDN/oab # Set-OabVirtualDirectory -Identity "$line\OAB (Default Web Site)" -InternalURL https://$FQDN/oab -externalurl https://$FQDN/oab confirm $false # Set Client Access Server Internal Uri set-clientaccessserver $line -AutoDiscoverServiceInternalUri https://$fqdn/autodiscover/autodiscover.xml # ECP setting Set-EcpVirtualDirectory -Identity "$line\ecp (Default Web Site)" -InternalURL https://$FQDN/ecp -externalurl https://$FQDN/ecp confirm:$false } } # End URL configuration function # DLP Fingerprint function function create-DLPfingerprint { CLS # Specify file for the DLP fingerprint $doc = read-host "Please enter the complete file path for the document you wsh to use for DLP Fingerprinting" $FingerPrint = Get-Content $doc -Encoding byte # Create the fingerprint write-host " " $description = read-host "Enter a description for the document to be fingerprinted" $DocumentFingerprint = New-Fingerprint -FileData $FingerPrint Description $description # Create Dataclassification write-host " " $classification = read-host "Please enter a name for the new data classification" write-host " " $description2 = read-host "Please enter a description for the data classification" New-DataClassification -Name $classification -Fingerprints $DocumentFingerprint -Description $description2 # Create transport rule based off the data classification write-host " " $rulename = read-host "Please enter a name for the transport rule related to DLP." write-host " " $NotifySender = read-host "Please enter a value for 'Notify Sender' [NotifyOnly | RejectMessage | RejectUnlessFalsePositiveOverride | RejectUnlessSilentOverride | RejectUnlessExplicitOverride]" write-host " " $mode = read-host "Please enter one of the following for the Transport Rule Mode [Audit | AuditAndNotify | Enforce]" write-host " " $sentToScope = read-host "For the Sent To Scope, please enter one of the following values [InOrganization | NotInOrganization | ExternalPartner | ExternalNonPartner]" New-TransportRule -Name $rulename -NotifySender $NotifySender -Mode $mode -SentToScope $senttoscope -MessageContainsDataClassification @{Name="$classification"} write-host " " Get-DataClassification $classification |ft write-host " " Get-TransportRule $rulename write-host " " write-host "Done creating the new Transport rule based off the DLP Fingerprint." -ForegroundColor green } # End DLP Fingerprint function # Start Server Settings function function Set-ServerSettings { CLS $servers = (get-exchangeserver).name write-host "Do you want change any of your servers event log sizes [y or n]? " -ForegroundColor Green -NoNewline $seteventlogs = read-host if ($seteventlogs -eq "y") { write-host " " write-host "Do you want to set the event logs for all servers the same size [y or n] " -ForegroundColor yellow -NoNewline $allorone = read-host if ($allorone -eq 'y') { write-host " " $answer1 = read-host "Would you like to set the size of your System Log [y or n]" if ($answer1 -eq "y") { write-host " " $syssize = read-host "What size would you like for your System Event log [i.e. 100MB]" $size = Invoke-expression $syssize foreach ($line in $servers) { limit-eventlog -computername $line "System" MaximumSize $size } } write-host " " $answer2 = read-host "Would you like to set the size of your Application Log [y or n]" if ($answer2 -eq "y") { write-host " " $appsize = read-host "What size would you like for your Application Event log [i.e. 100MB]" $size = Invoke-expression $appsize foreach ($line in $servers) { limit-eventlog -computername $line "Application" -MaximumSize $size } } write-host " " $answer3 = read-host "Would you like to set the size of your Security Log [y or n]" if ($answer3 -eq "y") { write-host " " $secsize = read-host "What size would you like for your Security Event log [i.e. 100MB]" $size = Invoke-expression $secsize foreach ($line in $servers) { limit-eventlog -computername $line "Security" MaximumSize $size } } write-host " " foreach ($line in $servers) { $customeranswer = read-host "Would you like to modify custom log limits on the $line server [y or n]" if ($customeranswer -eq "y") { $num = read-host "How many custom logs will you need to modify" $counter = 0 while ($counter -lt $num) { $logname = read-host "What is the name of the log you wish to modify" $logsize = read-host "Would you like to set the size of your $logname Log [i.e. 100MB]" limit-eventlog -computername $line $logname MaximumSize $logsize } } write-host " " } } if ($allorone -eq 'n') { foreach ($line in $servers) { write-host " " write-host "OK. Let's set all the servers individually" -ForegroundColor Green write-host " " $answer1 = read-host "Would you like to set the size of your System Log on $line [y or n]" if ($answer1 -eq "y") { $syssize = read-host "What size would you like for your System Event log" #translate to Int64 for use with limit-eventlog cmdlet $size = Invoke-expression $syssize limit-eventlog -computername $line "System" MaximumSize $size } write-host " " $answer2 = read-host "Would you like to set the size of your Application Log on $line [y or n]" if ($answer2 -eq "y") { $appsize = read-host "What size would you like for your Application Event log" #t ranslate to Int64 for use with limit-eventlog cmdlet $size = Invoke-expression $appsize limit-eventlog -computername $line "Application" MaximumSize $size } write-host " " $answer3 = read-host "Would you like to set the size of your Security Log on $line [y or n]" if ($answer3 -eq "y") { $secsize = read-host "What size would you like for your Security Event log" # translate to Int64 for use with limit-eventlog cmdlet $size = Invoke-expression $syssize limit-eventlog -computername $line "Security" MaximumSize $secsize } write-host " " $customeranswer = read-host "Would you like to modify custom log limits on the $line server [y or n]" if ($customeranswer -eq "y") { write-host " " $num = read-host "How many custom logs will you need to modify" write-host " " $counter = 0 while ($counter -lt $num) { $logname = read-host "What is the name of the log you wish to modify" $logsize = read-host "Would you like to set the size of your $logname Log" #translate to Int64 for use with limit-eventlog cmdlet $size = Invoke-expression $logsize limit-eventlog -computername $line $logname MaximumSize $size } } } } write-host " " write-host "All Event logs have been modifed as specified." ForegroundColor yellow write-host " " } write-host "Do you want change any of your servers message tracking log settings [y or n]? " -ForegroundColor Green -NoNewline $messagetrack = read-host if ($messagetrack -eq "y") { # Set the Message Tracking Log settings write-host " " write-host "Do you want to change the Message Tracking Log settings on your Exchange servers all the same [y or n] " -ForegroundColor yellow -NoNewline $Modify = read-host $servers = (get-transportservice).name if ($modify -eq "y") { write-host " " $maxage = read-host "What is the max age setting you want to configure your tracking logs with for all of your Exchange Servers [dd.hh:mm:ss]" write-host " " $maxdirsize2 = read-host "What is the maximum directory size you want to setup for all of your Exchange Servers (in MB)" $maxdirsize =[string]$maxdirsize2+"MB" write-host " " $maxfilesize2 = read-host "What is the mazimum log fize size you wish to setup on all Exchange Servers (in MB)" $maxfilesize = [string]$maxfilesize2+"MB" foreach ($line in $servers) { set-transportservice -identity $line MessageTrackingLogMaxAge $maxage -MessageTrackingLogMaxDirectorySize $maxdirsize -MessageTrackingLogMaxFileSize $maxfilesize } } else { foreach ($line in $servers) { write-host " " $maxage = read-host "What is the max age setting you want to configure your tracking logs with on $line [dd.hh:mm:ss]" write-host " " $maxdirsize = read-host "What is the maximum directory size you want to setup on $line (in MB)" $size = Invoke-expression $maxdirsize $maxfilesize = read-host "What is the maximum log fize size you wish to setup on $line (in MB)" $size2 = Invoke-expression $maxfilesize set-transportservice -identity $line MessageTrackingLogMaxAge $maxage -MessageTrackingLogMaxDirectorySize $size -MessageTrackingLogMaxFileSize $size2 } } } write-host "Do you want change any of your servers Outlook Anywhere settings [y or n]? " -ForegroundColor Green -NoNewline $OA = read-host if ($OA -eq "y") { # Set the Outlook Anywhere settings write-host " " write-host "Do you want to change the Outlook Anywhere settings on your Exchange servers all the same [y or n] " -ForegroundColor Yellow -nonewline $OAdecision = read-host $servers = (get-exchangeserver).name if ($OAdecision -eq "y") { write-host " " $SSL = read-host "Configure SSL Offloading [t or f]" if ($ssl -eq "t") {$SSL = $true} else {$ssl = $false} $iisauth = read-host "What IIS Authenticaiton methods do you want configure" $internalname = read-host "What is the internal host name for Outlook Anywhere" $externalname = read-host "What is the external name for Outlook Anywhere" $permission = read-host "Do you want to set a (1) default permission or (2) split the internal and external permissions [1 or 2]" if ($permission -eq "2") { # Set external configuration write-host "Enter the default permissions for external clients. Acceptable answers are:" write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs | Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $external = read-host "Your choice is" # Set external SSL $externalssl = read-host "Is SSL required for external connections (t or f)" if ($externalssl -eq "t") {$externalssl = $true} else {$externalssl = $false} write-host " " # Set internal configuration write-host "Enter the default permissions for internalclients" write-host "Acceptable answers are " -nonewline write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs | Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $internal = read-host "Your choice is" # Set internal SSL $internalssl = read-host "Is SSL required for internal connections (t or f)" if ($internalssl -eq "t") {$internalssl = $true} else {$internalssl = $false} write-host " " get-outlookanywhere | set-OutlookAnywhere ExternalClientAuthenticationMethod $external -ExternalClientsRequireSsl $externalSSL -SSLOffloading $ssl -ExternalHostName $externalname IISAuthenticationMethods $iisauth -InternalClientsRequireSsl $internalSSL -internalhostname $internalname } else { write-host "Enter the default permissions for internal and external clients" write-host "Acceptable answers are " -nonewline write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs| Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $default = read-host "Your choice is" get-outlookanywhere | set-OutlookAnywhere DefaultAuthenticationMethod $default -SSLOffloading $ssl ExternalHostName $externalname -IISAuthenticationMethods $iisauth internalhostname $internalname } } else { foreach ($line in $servers) { write-host " " write-host "Configure Outlook Anywhere for the server $line." -ForegroundColor Green write-host " " $cam = read-host "What client authentiction method(s) would you like to configure for Outlook Anywhere" $SSL = read-host "Configure SSL Offloading [t or f]" if ($ssl -eq "t") {$SSL = $true} else {$ssl = $false} $iisauth = read-host "What IIS Authenticaiton methods do you want configure" $internalname = read-host "What is the internal host name for Outlook Anywhere" $externalname = read-host "What is the external name for Outlook Anywhere" $permission = read-host "Do you want to set a (1) default permission or (2) split the internal and external permissions [1 or 2]" write-host " " if ($permission -eq "2") { # Set external configuration write-host "Enter the default permissions for external clients. Acceptable answers are:" write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs | Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $external = read-host "Your choice is" # Set external SSL $externalssl = read-host "Is SSL required for external connections (t or f)" if ($externalssl -eq "t") {$externalssl = $true} else {$externalssl = $false} write-host " " # Set internal configuration write-host "Enter the default permissions for internalclients" write-host "Acceptable answers are " -nonewline write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs | Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $internal = read-host "Your choice is" # Set internal SSL $internalssl = read-host "Is SSL required for internal connections (t or f)" if ($internalssl -eq "t") {$internalssl = $true} else {$internalssl = $false} write-host " " set-OutlookAnywhere -server $line ExternalClientAuthenticationMethod $external -ExternalClientsRequireSsl $externalSSL -SSLOffloading $ssl -ExternalHostName $externalname IISAuthenticationMethods $iisauth -InternalClientsRequireSsl $internalSSL -internalhostname $internalname } else { write-host "Enter the default permissions for internal and external clients. Acceptable answers are:" write-host "Basic | Digest | Ntlm | Fba | WindowsIntegrated | LiveIdFba | LiveIdBasic | WSSecurity | Certificate | NegoEx | OAuth | Adfs| Kerberos | Negotiate | LiveIdNegotiate | Misconfigured" -ForegroundColor Green write-host " " $default = read-host "Your choice is" set-OutlookAnywhere -server $line DefaultAuthenticationMethod $default -SSLOffloading $ssl ExternalHostName $externalname -IISAuthenticationMethods $iisauth internalhostname $internalname } } } } } # End Server Settings funtion # Start random mailbox function function random-mailboxes { # Prep Random mailboxes (version 1) $mbxcount = (get-mailbox | where {($_.RecipientTypeDetails -ne "DiscoveryMailbox") -and ($_.RecipientTypeDetails -ne "RoomMailbox")}).count $range = get-random -minimum 0 -maximum $mbxcount $mailbox = (get-mailbox | where {($_.RecipientTypeDetails -ne "DiscoveryMailbox") -and ($_.RecipientTypeDetails -ne "RoomMailbox")}).primarysmtpaddress # Create Random User List $counter = 0 $userlist = @() while ($counter -lt $range) { $position = get-random -minimum 0 -maximum $mbxcount $alias = $mailbox[$position].local+"@"+$mailbox[$position].domain $validation = $false # # foreach ($line in $userlist) { if ($userlist -contains $alias) { $validation = $true $counter-} $counter++ } if ($validation -eq $false) { # Put all the mailboxes into a list of unique results $global:userlist += @($alias) } } }# End random mailbox function # Start new email creation function Function create-emailps1 { $filepath = read-host "Enter the filename and path of the PS1 file to be run for email population [i.e. c:\temp\scripttorun.ps1]" $sendto = read-host "Do you want to send emails to (a) All mailboxes, (r) Random mailboxes or (c) use a CSV file" # Set the email server used for email relay $transport = (get-transportservice).name $smtpserver = $transport[0] if ($sendto -eq "a") { write-host " " write-host "This section is for sending test messages to all mailboxes" -ForegroundColor green write-host " " $noofcopies = read-host "How many test email messages to be sent per sender" $subject = read-host "Enter a subject line for the test message" $body = read-host "Enter a message body for the test" write-host "Do you want to add an attachment? [y or n] " nonewline -ForegroundColor Green $attach = read-host if ($attach -eq "y") { $attachment = read-host "Specify an attachement for the test email" } else { $attachment = $null} $mbxcount = ($mailboxes = Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -resultsize unlimited).count $mbxcount-$mailboxes = (Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -resultsize unlimited).primarysmtpaddress # Create one line per mailbox foreach ($line in $mailboxes) { # Recipient - starts from the end of the mailbox variable $recipient = $mailboxes[$mbxcount] # Sender starts from the beginning of the mailbox variable $sender = $line $variable = '$counter' add-content $filepath "$variable = 0" add-content $filepath "while ('$counter' -lt $noofcopies) {" if ($attachment -ne $null) { add-content $filepath "send-mailmessage -from '$sender' to '$recipient' -subject '$subject' -body '$body' -smtpserver '$smtpserver' -attachment '$attachment'" } else { add-content $filepath "send-mailmessage -from '$sender' to '$recipient' -subject '$subject' -body '$body' -smtpserver '$smtpserver'" } add-content $filepath "$variable++" add-content $filepath "}" $mbxcount-} } if ($sendto -eq "r") { write-host " " write-host "This section is for sending test messages to random mailboxes" -ForegroundColor green write-host " " $noofcopies = read-host "How many test email messages to be sent per sender" $subject = read-host "Enter a subject line for the test message" $body = read-host "Enter a message body for the test" write-host "Do you want to add an attachment? [y or n] " nonewline -ForegroundColor Green $attach = read-host if ($attach -eq "y") { $attachment = read-host "Specify an attachement for the test email" } else { $attachment = $null} # Choose random mailboxes random-mailboxes $sender = $userlist random-mailboxes $recipient = $userlist # Create one line per mailbox foreach ($line in $sender) { foreach ($line2 in $recipient) { $sender = $line $recipient = $line2 $variable = '$counter' add-content $filepath "$variable = 0" add-content $filepath "while ($variable -lt $noofcopies) {" if ($attachment -ne $null) { add-content $filepath "send-mailmessage -from '$sender' -to '$recipient' -subject '$subject' -body '$body' -smtpserver '$smtpserver' -attachment '$attachment'" } else { add-content $filepath "send-mailmessage -from '$sender' -to '$recipient' -subject '$subject' -body '$body' -smtpserver '$smtpserver'" } add-content $filepath "$variable++" add-content $filepath "}" } } } if ($sendto -eq "c") { write-host " " write-host "This section is for sending test messages using a CSV file" -ForegroundColor green write-host " " # CSV format should be sender,recipient,subject,body,attachment,noofcopies $csvfile = read-host "Specify a CSV file to read from" $csv = import-csv $csvfile $filepath = read-host "Enter the filename and path of the PS1 file to be run for email population [i.e. c:\temp\scripttorun.ps1]" # $transport = "lab09-ex01" foreach ($line in $csv) { $sender = $line.sender $recipient = $line.recipient $subject = $line.subject $body = $line.body $attachment = $line.attachment $noofcopies = $line.noofcopies $variable = '$counter' add-content $filepath "$variable = 0" add-content $filepath "while ($variable -lt $noofcopies) {" add-content $filepath "send-mailmessage -from '$sender' -to '$recipient' -subject '$subject' -body '$body' -smtpserver '$smtpserver' -attachment '$attachment'" add-content $filepath "$variable++" add-content $filepath "}" } } $global:filepath $decision = read-host "Do you want to run the PS1 file (1) manually or (2) schedule it" if ($decision -eq "2") { schedule-emails } write-host " " write-host "Do you want to run it now? [y or n] " foregroundcolor yellow -nonewline $decision2 = read-host if ($decision2 -eq "y") { write-host " " write-host "OK. Running the script called $filepath" invoke-expression $filepath $filepath = $null } } # End new email creation function # Start the schedule task function function schedule-emails { $name = read-host "Name of the scheduled job in PowerShell" $frequency = read-host "How often do you want the emails tobe sent [hourly, daily, weekly]" $time = read-host "At what time should the task run (not hourly) [ie 12:00AM, 4:00PM]" $range = read-host "Do you want this task to (1) run indefinately or (2) run for a period of time [1 or 2]" if ($range -eq "2") { $start = read-host "Enter a start date [1/1/2015]" $stop = read-host "enter a stop date [4/1/15]" $duration = new-timespan -start $start -end $stop } else { $duration = "([TimeSpan]::MaxValue)" } # Get days of the week for weekly task if ($frequency -eq "weekly") { $weeks = read-host "Trigger the script every how many weeks [1 or 2 or 3 or...]" $numdays = read-host "How many days of the week do you want to schedule for[# 1 - 7]" $daysofweek = @() $counter = 0 while ($counter -lt $numdays){ $dow = read-host "Enter a number for the day of the week [Sunday, Monday, Tuesday, etc]" $counter++ $daysofweek += ,@($dow) } $daysofweek $trigger = New-JobTrigger –Weekly –DaysOfWeek $daysofweek –At $time weeksinterval $weeks $trigger | fl } if ($frequency -eq "hourly") { $hourly = read-host "Enter the number of hours between jobs" $startdate = read-host "Enter a start date [i.e. 1/1/2015]" $trigger = New-JobTrigger -Once -At "$startdate $time" RepetitionInterval (New-TimeSpan -Hour $hourly) -RepetitionDuration ([TimeSpan]::MaxValue) $trigger | fl } if ($frequency -eq "daily") { $days = read-host "What is the interval (in days) that the script should run" $trigger = New-JobTrigger –daily –At $time -daysinterval $days $trigger |fl } Register-ScheduledJob -Name $name -FilePath $filepath -Trigger $trigger } # End the schedule task function Do { if ($RebootRequired -eq $true){Write-Host "`t`t`t`t`t`t`t`t`t`n`t`t`t`tREBOOT REQUIRED!`t`t`t`n`t`t`t`t`t`t`t`t`t`n`t`tDO NOT INSTALL EXCHANGE BEFORE REBOOTING!`t`t`n`t`t`t`t`t`t`t`t`t" -backgroundcolor red -foregroundcolor black} if ($opt -ne "None") {Write-Host "Last command: "$opt foregroundcolor Yellow} $opt = Read-Host $menu switch ($opt) { 1 {# Create databases and replicas create-database dag-check } 2 {# Create Mailboxes create-mailboxes } 3 {# Create Distribution Groups $create = read-host "Are all mailboxes created [y or n]" if ($create -eq "y") { create-distributiongroups } else { write-host "Please create mailboxes before creating any DL's!" } } 4 {# Create Shared Mailboxes create-sharedmailboxes } 5 {# Create Rooms $choice = read-host "Do you want to [1] create rooms or [2] rooms and roomlists?[1 or 2]" if($choice -eq 1) { create-roommailboxes } else { # Added an move advanced option (1.3) New-RoomList } } 6 {# Populate email create-emailps1 } 7 {# Populate calendars # Create sample calendar entries and exported it to a PST file # Import these into random mailboxes write-host "This function assumes you have the correct rights." -fore red write-host " " ] file start-sleep 5 Create-CalendarEvents } 8 {# Populate Tasks # Create sample calendar entries and exported it to a PST # Import these into random mailboxes write-host "This function assumes you have the correct rights." -fore red write-host " " start-sleep 5 Create-Tasks } 9 {# DLP Policy Creation write-host " " write-host "Create DLP Policy [y or n]?" -nonewline ForegroundColor green $dlp = read-host if ($dlp -eq "y") { invoke-expression "c:\scripts\XMLScript-Lab-1.3.ps1" } write-host" " write-host "Create DLP Policy with fingerprinting? [y or n]" -nonewline -ForegroundColor yellow $dlp = read-host if ($dlp -eq "y") { create-DLPfingerprint } } 10 {# Create retention Policies create-retentionpolices } 11 {# Configure quotas configure-quotas } 12 {# Configure disclaimers Check-OldDisclaimers Configure-NewDisclaimers } 13 {# Configure Transport Rules CLS write-host " " write-host "This menu option is not ready yet for testing." -ForegroundColor Red write-host " " start-sleep 5 CLS } 14 {# Configure Other Settings write-host " " write-host "This part of the script will configure event log sizes, message tracking log options, and Outlook Anywhere" ForegroundColor yellow start-sleep 2 Set-ServerSettings } 15 { # Mobile Devices create-mobiledevicepolicy } 16 { # OWA Policies create-OWApolicy } 17 { # Enabling Archives enable-archives } 18 { # Configure Apps configure-Apps } 19 { # Configure Journaling configure-journaling } 20 { # Configure Delegation configure-delegation } 21 { # Configure Archive Quotas Configure-ArchiveQuotas } 22 { #Configure dynamic DLs create-dynamicdistributiongroups } 23 { # Configure URLs Configure-URLs } 24 {$location = read-host "Where is the MobileDeviceMailboxPolicy.ps1 file location? Please provide the full path [c:\scripts\MobileDeviceMailboxPolicy.ps1] " invoke-expression $location } 25 {$location = read-host "Where is the ChangeOWAvDirSettings.ps1 file location? Please provide the full path [c:\scripts\Change-OWAvDirSettings.ps1] " invoke-expression $location } 26 {$location = read-host "Where is the OWAAuthentication.ps1 file location? Please provide the full path [c:\scripts\OWAAuthentication.ps1] " invoke-expression $location } 27 {$location = read-host "Where is the OWAMailboxPolicy.ps1 file location? Please provide the full path [c:\scripts\OWAMailboxPolicy.ps1] " invoke-expression $location } 50 {# Assign impersonation rights to the current user account add-impersonation } 97 {# Remove all the above configurations CLS write-host " " write-host "This menu option is not ready yet for testing." -ForegroundColor Red write-host " " start-sleep 5 CLS # Remove mailboxes, quotas, retention policies, impersonation, distribution groups, etc } 98 {# All of the above steps - walk through each function CLS write-host " " write-host "This menu option is not ready yet for testing." -ForegroundColor Red write-host " " start-sleep 5 CLS } 99 {# Exit if (($WasInstalled -eq $false) -and (Get-Module BitsTransfer)){ Write-Host "BitsTransfer: Removing..." -NoNewLine Remove-Module BitsTransfer Write-Host "`b`b`b`b`b`b`b`b`b`b`bremoved! " ForegroundColor Green } popd Write-Host "Exiting..." Stop-Transcript } default {Write-Host "You haven't selected any of the available options. "} } } while ($opt -ne 99)