Showing posts with label Exchange. Show all posts
Showing posts with label Exchange. Show all posts

Wednesday, March 11, 2015

Clean the exchange server logfiles

At a client I found that disks were filling up with logfiles. Most but not all logfiles were cleared automatically after 7 or 14 days but that left a few logfiles filling up the disk..


I created a scheduled task which runs every night (after the backup run) and removes all old logfiles:

It is a powershell one liner:

powershell.exe Get-ChildItem 'c:\Program Files\Microsoft\Exchange Server\V15\Logging','C:\inetpub\logs' -Directory | Get-ChildItem -Include '*.log','*.blg' -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item

 This script will remove all logfiles older than 7 days.

Monday, February 2, 2015

Outlook for Android and iOS


A lot of sites are now reporting the insecurity of the application Outlook which appeared januari 29th in the Apple AppStore. (Warning – Microsofts Outlook app for iOS breaks your company security) and (Microsoft Wants to Improve Your Mobile Email Experience with the New Outlook for iOS and Android) This is the same application (some rebranding has been done) as the Accompli app which is now purchased by Microsoft.

What is the problem with this app?
It is a good app. It looks very need, but to do what is does it needs a little something from you and it will store this information on the servers in the cloud (Now at AWS but soon Microsoft Azure)
What is this information it needs?.... That is your Username and Password.
What does it do with this information? .... It starts downloading your entire mailbox, and caches this in the cloud.
Why is this a problem? .... For a private person not so much.... You probably share all the information on Facebook, twitter etc anyway, and don't have secrets in your mail which other instances / agencies are interested in.... But for companies this might be a large issue. They usually have something setup which is referred to as a company security policy. This policy mostly states the following items:

  • Device must have a pincode or password
  • Device must be encrypted
  • In case of lost the device must be wiped
  • etc.

All these things are not possible with the new App. From an App it is NOT possible to set device settings such as encryptions and passwords. A wipe is also not possible (In some cases the mailbox is reported to be removed)....


What to do now?
Firewall
Block the application from entering your network. If possible do this on your firewall with an User-Agent filter.
Filter for the following user agents:

  • Outlook-iOS-Android
  • Outlook for iOS and Android

Exchange (Exchange 2010 and Higher)
You can also add an rule on your Exchange server which will block access to the mail environment.
New-ActiveSyncDeviceAccessRule -Characteristic DeviceModel -QueryString "Outlook for iOS and Android" -AccessLevel Block
Block or Quarantine the Outlook for iOS and Android App in Exchange Server and Office 365

Future
Microsoft is busy with this application, updating and modifying it. So it is important to keep an eye on the changes which will occur in this application.
I do think that the application has a lot of potential and is a way to go, but first some issues have to be resolved. But for now "Hands Off"

Tuesday, January 20, 2015

Exchange services

Today I was at a client which had an issue with their Exchange environment. They were installing updates and one of the Exchange servers was giving trouble after that.
When I logged on to the server I noticed that all services were disabled, and since I am lazy I scripted the recovery for this ;-)

I though I shared it with you. Maybe there can be a check before if the service is running or not, or if it is really disabled.. But mostly this is a quick fix for your Exchange environment.

get-service "msexcha*" | Set-Service -StartupType automatic
get-service HostControllerService | Set-Service -StartupType automatic
get-service wsbexchange | Set-Service -StartupType automatic
get-service FMS | Set-Service -StartupType automatic
get-service W3SVC | Set-Service -StartupType automatic
get-service IISADMIN | Set-Service -StartupType automatic
get-service pla | set-service -startuptype automatic
get-service RemoteRegistry | set-service -startuptype automatic
get-service SearchExchangeTracing | Set-Service -StartupType automatic
get-service "MSExchangeImap4" | set-service -StartupType manual
get-service "MSExchangeImap4BE" | set-service -StartupType manual
get-service "MSExchangePop3" | set-service -StartupType manual
get-service "MSExchangePop3BE" | set-service -StartupType manual

get-service HostControllerService | start-service
get-service FMS | start-service
get-service "msexcha*" -StartupType automatic | start-service
get-service wsbexchange | start-service
get-service W3SVC | start-service
get-service WinRM | start-service
get-service pla | start-service
get-service RemoteRegistry | start-service
get-service IISADMIN | start-service
get-service SearchExchangeTracing  | start-service

Friday, January 25, 2013

In the pocket: Core Solutions of MS Exchange Server 2013 Customer Preview

Today I saw that another IT pro passed his exam and I thought about the beta exams I did for Microsoft Exchange 2013...

So I took al little trip to https://www.register.prometric.com/CandidateHistory.asp and found out that I passed the "Core Solutions of MS Exchange Server 2013 Customer Preview" (071-341) exam... To bad that I failed the "Advanced Solutions of MS Exch Serv 2013 Customer Preview" (070-342) exam..

But with the lack of experience I was able to obtain since I couldn't install Exchange 2013 in my Exchange 2010 environment I think I did rather well with only reading about all there is on Technet and other Tech blogs...

I hope to find the time to install Exchange 2013 soon in my environment and update all the scripts to this version...

Monday, January 21, 2013

Exporting mailboxes to PST-files the easy way

When doing a cross domain migration it can be usefull to export the mailboxes to a PST file.

When doing this for a large amount of mailboxes it can be useful to use a script to automate this...

As I am lazy, I searched the internet for such a script, and found one from Steve Goodman which was close to what I wanted.. But as needy as I am, I needed more.

I modified, and added to the script which you find below. And is is as good as I am going to make it. It works like a charm (as I do say so myself)

Also made it so that if you are going to export a lot of mailboxes the target share and the source servers won't die on you you can set the maximum concurrent to a number your environment will survive.
The script will start the first batch, wait until completion, and than start the second batch.

When finished it will write some info to the report folder, and the logs for the completed and the failed requests...

Thanks go to Jeff Wouters which reviewed the script for me. And to his blog for the Add-Module function, which gave me a good idea for an add-SnapIN function which does basically the same but than for SnapIns.. so if you run the script multiple times you won't get an error :-)

# Exchange 2010 SP1 Mailbox Export Script
# Original script from : Steve Goodman (http://www.stevieg.org/2010/07/using-the-exchange-2010-sp1-mailbox-export-features-for-mass-exports-to-pst/)
# input from Jeff Wouters ( www.jeffwouters.nl)
# deviations from original script:
# - option to export all in the organisation
# - option to export all in a list
# - option to include archive mailboxes
# - option to exclude dumpster
# - option to set a maximum concurrent exports
# - no need to run from Exchange PowerShell. Needed library is loaded at runtime
$starttime = get-date -displayhint time
###############
# Settings    #
###############

# Pick ONE of the two below. If you choose both, it will use $Server.
$Server
$Database
$list = "\\server\share\users1.csv"

# Share to export mailboxes to. Needs R/W by Exchange Trusted Subsystem
# Must be a UNC path as this is run by the CAS MRS service.
$ExportShare = "\\server\share\pst\"
if (!(test-path -path $ExportShare -pathtype container))
{
 mkdir $ExportShare
}

# After each run a report of the exports can be dropped into the directory specified below. (The user that runs this script needs access to this share)
# Must be a UNC path or the full path of a local directory.
$ReportShare = "\\server\share\log\"
if (!(test-path -path $ReportShare -pathtype container))
{
 mkdir $ReportShare
}

# Shall we remove the PST file, if it exists beforehand? (The user that runs this script needs access to the $ExportShare share)
# Valid values: $true or $false
$RemovePSTBeforeExport = $true

# Do we want to include Archive Mailboxes
$IncludeArchive = $true

# Do we want to exclude dumpster
# currently not working as intended. workarround in place
$ExcludeDumpster = $false

# How many concurrent exports do we want?
# This must be an even number (2, 4, 6, 50, 100, 200, 1000 etc)
$maxConcurrentExports = 200

###############
# Code        #
###############

# function created by Jeff Wouters (www.jeffwouters.nl)
function Check-LoadedModule
{
  Param( [parameter(Mandatory = $true)][alias("Module")][string]$ModuleName)
  $LoadedModules = Get-Module | Select Name
  if (!$LoadedModules -like "*$ModuleName*") {Import-Module -Name $ModuleName}
}

# Deviation from Jeff Wouters function but for PSAddins
function Check-LoadedSnapIN
{
  Param( [parameter(Mandatory = $true)][alias("SnapIN")][string]$SnapINName)
 if ( (Get-PSSnapin -Name $SnapINName -ErrorAction SilentlyContinue) -eq $null )
 {
     Add-PsSnapin $SnapINName
 }
}

# If Archives are included we get 2 exports at a time. so we need to divide the maximum by 2
if ($includeArchive){
 $maxConcurrentExports = $maxConcurrentExports / 2
}

# load the Exchange powershell snapin if not loaded
Check-LoadedSnapIN Microsoft.Exchange.Management.PowerShell.E2010

# this function will create the MailboxExportRequests.
function exportMailbox ([String]$CurrentUser) {
     if ($RemovePSTBeforeExport -eq $true -and (Get-Item "$($ExportShare)\$($CurrentUser).PST" -ErrorAction SilentlyContinue))
     { 
         Remove-Item "$($ExportShare)\$CurrentUser.PST" -Confirm:$false -ErrorAction SilentlyContinue
         Remove-Item "$($ExportShare)\$CurrentUser-Archive.PST" -Confirm:$false -ErrorAction SilentlyContinue
     }
     if ($ExcludeDumpster){ # workarround if else. Would rather place this inline in the vode.
      New-MailboxExportRequest -BatchName $BatchName -Mailbox $CurrentUser -FilePath "$($ExportShare)\$CurrentUser.pst" -ExcludeDumpster
      if ($IncludeArchive){
       New-MailboxExportRequest -BatchName $BatchName -Mailbox $CurrentUser -FilePath "$($ExportShare)\$CurrentUser-Archive.pst" -IsArchive -ExcludeDumpster
      }
     } else {
      New-MailboxExportRequest -BatchName $BatchName -Mailbox $CurrentUser -FilePath "$($ExportShare)\$CurrentUser.pst"
      if ($IncludeArchive){
       New-MailboxExportRequest -BatchName $BatchName -Mailbox $CurrentUser -FilePath "$($ExportShare)\$CurrentUser-Archive.pst" -IsArchive
      }
  }     
}

# This function makes the script wait for completion of all exports.
function waitForCompletion {
 while ((Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"}))
 {
     clear
     Write-Output "Waiting for the exports to complete"
     Get-MailboxExportRequest -BatchName $BatchName | Get-MailboxExportRequestStatistics | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"} | Out-Default | Format-Table
     sleep 60
 }
}

# Make batch name
$date=Get-Date
$BatchName = "Export_$($date.Year)-$($date.Month)-$($date.Day)_$($date.Hour)-$($date.Minute)-$($date.Second)"

if ($ExcludeDumpster){
 $additionalParm = "-ExcludeDumpster $true"
} else {
 $additionalParm = ""
}

# the collection of what to be export
if ($Server)
{
 write-output "Using Server"
    if (!(Get-ExchangeServer $Server -ErrorAction SilentlyContinue))
    {
        throw "Exchange Server $Server not found";
    }
    if (!(Get-MailboxDatabase -Server $Server -ErrorAction SilentlyContinue))
    {
        throw "Exchange Server $Server does not have mailbox databases";
    }
    $Mailboxes = Get-Mailbox -Server $Server -ResultSize Unlimited
} elseif ($Database) {
 write-output "Using database" 
    if (!(Get-MailboxDatabase $Database -ErrorAction SilentlyContinue))
    {
        throw "Mailbox database $Database not found"
    }
    $Mailboxes = Get-Mailbox -Database $Database -ResultSize Unlimited
} elseif ($list) {
 write-output "Using list: $list"
 $userlist = Import-CSV $list
} else {
    write-output "None of the above, so exporting all mailboxes.."
    $mailboxes = Get-Mailbox -ResultSize Unlimited
} 

# The Export
if ($list){
 Write-Output "Queuing $($userlist.Count) mailboxes as batch '$($BatchName)'"
 $teller = 0
 # Queue all mailbox export requests
 foreach ($user in $userlist)
 {
     $teller = $teller + 1
     $curuser =  $user.SamAccountName
     exportMailbox $curuser
     if ($teller -gt $maxConcurrentExports){
  Write-Output "Waiting for batch to complete"
  # Wait for mailbox export requests to complete
  waitForCompletion 
  $teller = 0
     }
 }  
 # Wait for mailbox export requests to complete
 waitForCompletion
}elseif ((!$Mailboxes) -and (!$Mailboxes.Count)) {
    throw "No mailboxes found on $Server or single Mailbox."
} else {
 Write-Output "Queuing $($Mailboxes.Count) mailboxes as batch '$($BatchName)'"
 # Queue all mailbox export requests
 $teller = 0
 foreach ($Mailbox in $Mailboxes)
 {
     $teller = $teller + 1
     exportMailBox $Mailbox.alias
     if ($teller -gt $maxConcurrentExports){
  Write-Output "Waiting for batch to complete"
  # Wait for mailbox export requests to complete
  waitForCompletion 
  $teller = 0
     }
 }
 # Wait for mailbox export requests to complete
 waitForCompletion
}

# Write reports if required
if ($ReportShare)
{
    Write-Output "Writing reports to $($ReportShare)"
    $Completed = Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -eq "Completed"} | Get-MailboxExportRequestStatistics | Format-List
    if ($Completed)
    {
        $Completed | Out-File -FilePath "$($ReportShare)\$($BatchName)_Completed.txt"
    }
    $Incomplete = Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -ne "Completed"} | Get-MailboxExportRequestStatistics
    if ($Incomplete)
    {
        $Incomplete | Format-List | Out-File -FilePath "$($ReportShare)\$($BatchName)_Incomplete_Report.txt"

  if (!$list){
   $list = "$($ReportShare)\$($BatchName)_failedpst.csv"
  }
  set-content -Value "Failed-PST" -Path $list".new"
  foreach ($woops in $Incomplete) {
   add-content -Value $woops.FilePath -Path $list".new"
  }

    }
}

$endtime = get-date -displayhint time

$runtimefile = "$($ReportShare)\$($BatchName)_runtime.txt"
$runtimeentry0 = $starttime.tostring() + ' - ' + $endtime.tostring()
$runtimeentry1 = "Completed exports: " + $completed.count
$runtimeentry2 = "Failedexports: " + $Incomplete.count
$runtimeentry3 = "Errored users:"
$runtimeentry4 = ( get-content -Path $list".new" | out-string)
Set-Content -Value $runtimeentry0 -Path $runtimefile
add-content -Value $runtimeentry1 -Path $runtimefile
add-content -Value $runtimeentry2 -Path $runtimefile
add-content -Value $runtimeentry3 -Path $runtimefile
add-content -Value $runtimeentry4 -Path $runtimefile

# Remove Requests
Write-Output "Removing requests created as part of batch '$($BatchName)'"
Get-MailboxExportRequest -BatchName $BatchName | Remove-MailboxExportRequest -Confirm:$false

Thursday, September 27, 2012

Create an Import Export Management Group with rights

To be able to use the other script to import PST Files, you first must have the permission to do so.

Since I am in favor of RBAC I created a little script to create an Exchange Import and Export Management Group, add the current user to this group and assign the appropriate rights to the group.

# To be able to import PST files you must be member of the Import Export Management Role.
# Bas Steelooper, XOBIT IT Services
# 
# This script will create an AD Group in the users OU named Exchange-ImportExport-Management
# And add the current user to this group.
# You have to logoff and logon again to use the newly acquired rights

# Configure here the name of the group to create
$GroupName = "Exchange-ImportExport-Management"

#============================
# Do not edit below this line
#============================

#Prepare the needed modules
Import-Module ActiveDirectory
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

# Create the AD Group as a Universal Group
New-ADgroup -Name $GroupName -GroupScope 2

# Add the current logged on user to the Group
Add-ADGroupMember -Identity $GroupName $env:username

# Assign the Import Export Rights to the Group
New-ManagementRoleAssignment -Name "ImportExport-Management" -SecurityGroup $GroupName -Role "Mailbox Import Export"


Monday, September 24, 2012

Importing a ####-Load of PST Files into Exchange

For a migration we needed to import a lot of PST files into the mailboxes of migrated users.. Since I am an IT guy, and therefor lazy, I created a script to do this.

This script creates a folder for each PST file with the name: "Import ()"

Prereqs for the script are:
* For each user with to be imported PST files create a folder with the first part of the emailadres (everything in front of the @-sign)
* add the PST files in the appropriate folder
* Edit the first two lines of the script to point to the share where the data resides, and the domainname with the @-Sign
* User must have the Import and Export management role assigned

# PST Import script.
# Bas Steelooper, XOBIT IT Services
# 
# This script will import the PST files from a given location.
# The PST files must reside in a folder which is named as the part of the emailadres in front of the @-sign
# 
# This script will import each folder one at a time and cleanup all the completed imports
# With the command Get-MailBoxImportRequest you can view all the failed import requests

# Configure the parameters. 
# $pstpath contains the share location where the PST Files are stored. ( The AD Computer account must have access to this location)
# $emaildomain contains the rest of the emailadres for all users
# $forceimport if $TRUE thePST-File will be forced imported, items which cannot be imported are skipped. Default is $FALSE
$pstpath = "\\<server>\<share>\UsersPSTData"
$emaildomain = "@steelooper.com"
$forceimport = $TRUE

#============================
# Do not edit below this line
#============================

#Load the Exchange powershell Snap-IN
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

get-ChildItem $pstpath | Foreach-object{ 

 $curuser = ""
 $curuser = $_
 $PSTFiles = get-ChildItem $pstpath\$curuser 
 $PSTFiles | Foreach-Object{ 
  if ($forceimport) {
   New-MailboxImportRequest -BatchName $curuser -BadItemLimit 200 -AcceptLargeDataLoss -Name $_ -MailBox $curuser$emaildomain -FilePath $pstpath\$curuser\$_ -TargetRootFolder "INBOX/Import ($_)"
  }
  else {
   New-MailboxImportRequest -BatchName $curuser -Name $_ -MailBox $curuser$emaildomain -FilePath $pstpath\$curuser\$_ -TargetRootFolder "INBOX/Import ($_)"
  }
 }

 while ((Get-MailboxImportRequest -BatchName $curuser | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"}))
 { 
  sleep 60
 }
 Get-MailboxImportRequest -BatchName $curuser | Where {$_.Status -eq "Completed"} | Remove-MailboxImportRequest -Confirm:$false;
}