Category Archives: Exchange

Import Exchange On-Premiese PowerShell Module into your PowerShell ISE console

When working with on-premises Exchange there may be a requirement to create a PowerShell script using PowerShell ISE. Even if you run ISE on a Exchange Server, you are unable to get the Exchange cmdlets in ISE. So whats theworkaround for this is?

Important: Getting Exchange Cmdlets on a client machine

If you are trying to add the Exchange cmdlets to your client machine then you will need to Install the Exchange Management Tools from the Exchange installation media on your device.

Importing the Exchange Cmdlets into PowerShell ISE

The following commands allow the import of the Exchange Management Cmdlets into PowerShell ISE. They are slight different for the listed versions of Exchange.

Exchange 2007

Use the following Add-PSSnapin to bring the cmdlets into PowerShell ISE

 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin; 

Exchange 2010

Use the following Add-PSSnapin to bring the cmdlets into PowerShell ISE

 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; 

Exchange 2013, 2016, 2019

Use the following Add-PSSnapin to bring the cmdlets into PowerShell ISE

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; 

Exchange Online

If you require the Exchange Online PowerShell Modules, you will need to install the new ExchangeOnlineManagement modules from the PowerShell Gallery.

The Author – Blogabout.Cloud

Do I have duplicate Recipient Alias within my Exchange organization?

So do you know if you have duplicate recipient alias within your Exchange organisation? Heres a quick script that will look at your Exchange Environment and download all recipient address into a handy csv file you to play with.

The script

$start = [datetime]::Now
Start Transcript
Start-Transcript -Path "$env:USERPROFILE\Desktop\Mailbox Alias\mailboxaliaslog.txt"
$Mailboxes = Get-Recipient -ResultSize Unlimited -RecipientType UserMailbox |
Sort-Object -Property @{ Expression = { $_.EmailAddresses.Count } } -Descending
$Results = foreach( $Mailbox in $Mailboxes ){
$Stats = $Mailbox | Get-MailboxStatistics

$Properties = [ordered]@{ FirstName = $Mailbox.FirstName LastName = $Mailbox.LastName DisplayName = $Mailbox.DisplayName TotalItemSize = $Stats.TotalItemSize PrimarySmtpAddress = $Mailbox.PrimarySmtpAddress } $AltAddresses = $Mailbox.EmailAddresses | Where-Object { $_ -match '^smtp:' -and $_ -ne $Mailbox.PrimarySmtpAddress } $i = 1 Write-Host ('INFO: Working {0}.PrimarySmptAddress' -f $Mailbox) foreach( $Address in $AltAddresses ){ $Properties.Add( ('AltAddress{0}' -f $i), $Address -replace '^smtp:' ) $i++ } [pscustomobject]$Properties }

$Results |
Export-Csv -Path "$env:USERPROFILE\desktop\MailboxAliasReport.csv"
$end = [datetime]::Now
$resulttime = $end - $start
Stop Transcript
Write-Host ('Execution : {0}Days:{1}Hr:{2}Min:{3}Sec' -f $resultTime.Days, $resultTime.Hours, $resultTime.Minutes, $resultTime.Seconds)


Get-RecipientAlias (259 downloads)

Discovering Distribution Lists using PowerShell

Do you have a requirement to understand how many Distribution Lists exist within your Exchange organization or need to understand if they actually being utilized? Well, this is something I have come across recently while working for the customer. They have a mass of distribution lists across their organization which they are trying to tidy up before migrating to Office 365. The organisation I was working for had over 100,000 distributions list but the state of them was unknown so what challenges did I face?

The challenges faced

  • Unknown the number of DLs that had 0 members
  • Unknown the number of DLs that had 0 managers
  • Unknown the number of DLs that had invalid characters

The solution… PowerShell

So the following script was created to obtain the all the attributes listed before, this enable to put together a business case for which distribution lists should be deleted and which should be migrated.

  • Distribution List Name
  • SamAccountName
  • GroupType
  • DistinguishedName
  • Managedby
  • memberdepartrestriction
  • memberjoinrestriction
  • primartysmtpaddress
  • Number of Members
# Call Distribution Lists
$dist = @(Get-DistributionGroup -resultsize unlimited)
# Start Transcript
Start-Transcript -Path $env:USERPROFILE\desktop\transcript.txt
# Report on Distribution List
foreach ($dl in $dist)
$count =@(Get-DistributionGroup $dl.samaccountname).count
$report = New-Object -TypeName PSObject
$report | Add-Member -MemberType NoteProperty -Name 'Group Name' -Value $dl.Name
$report | Add-Member -MemberType NoteProperty -Name 'samAccountname' -Value $dl.samaacountname
$report | Add-Member -MemberType NoteProperty -Name 'Group Type' -Value $dl.grouptype
$report | Add-Member -MemberType NoteProperty -Name 'DN' -Value $dl.distinguishedName
$report | Add-Member -MemberType NoteProperty -Name 'Manager' -Value $dl.managedby
$report | Add-Member -MemberType NoteProperty -Name 'Member Depart Restriction' -Value $dl.memberdepartrestriction
$report | Add-Member -MemberType NoteProperty -Name 'Member Join Restriction' -Value $dl.memberjoinrestriction
$report | Add-Member -MemberType NoteProperty -Name 'PrimarySMTPAddress' -Value $dl.primartysmtpaddress
$report | Add-Member -MemberType NoteProperty -Name 'Number of Members' -Value $count
Write-Host ('INFO: {0} has {1} members' -f $, ($count))
$reportoutput += $report
# Stop Transcript
# Report
$reportoutput | Export-Csv -Path $env:USERPROFILE\desktop\DistributionListReport.csv -NoTypeInformation -Encoding UTF8

The Author – Blogabout.Cloud

Counting Exchange/Exchange Online Mailboxes with a specified SMTP Domain

When working with large organisations that have multiple SMTP Domains, you may run into a requirement where you need to know. How many mailboxes have as their PrimarySMTPAddress or have listed as their EmailAddress.

Using the below PowerShell snippet you can find out exactly

# Primary SMTP Address
get-mailbox -resultsize unlimited | where {$_.primarysmtpaddress -like "*"} | Measure-Object

# Email Address
get-mailbox -resultsize unlimited | where {$_.emailaddress -like "*"} | Measure-Object


The Author – Blogabout.Cloud