SlideShare a Scribd company logo
1 of 35
PowerShell Tips & Tricks
for Exchange
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Agenda
• Introduction
• Exchange & PowerShell
• Tips & Tricks
– PowerShell scripting
– Cmdlet Extension Agents
• Demo
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
• Jaap Wesselius
• Independent Consultant
• Exchange MVP (8yrs)
• jaap@wesselius.info
• @jaapwess
• www.jaapwesselius.com
• Michel de Rooij
• Consultant @ Conclusion FIT
• Exchange MVP
• michel@eightwone.com
• @mderooij
• www.eightwone.com
• TheUCArchitects.com
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Introduction
• Who attended Sigi Jagott’s session?
• PowerShell is a command-line environment
• First introduced for Windows 2003
– Codename ‘Monad’
• Exchange Management Shell is add-on for
PowerShell
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Exchange & PowerShell
• On-Premises
– PowerShell 1.0 (EX2007)
– PowerShell 2.0 (EX2010)
– PowerShell 4.0 (EX2013)
• Exchange Online
– PowerShell 4.0
• Which version am I running?
– $PSVersionTable
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
PowerShell basics
• Verbs and Nouns
– Get-, Set-, New-, Enable-, Remove-
– Mailbox, DistributionGroup, ExchangeServer etc.
• Works with objects which are loaded in memory
• Processed/Manipulated in Memory
– This can be very inefficient when not properly executed!
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Connecting with PowerShell
• Implicit Remoting
$ExchSession= New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri http://exchange.contoso.com/PowerShell
-Authentication Kerberos
Import-PSSession $ExchSession
• EXO: Uri https://ps.outlook.com/powershell/, Basic auth &
AllowRedirection
• Use -Prefix to import cmdlets as Verb-PrefixNoun, e.g. Get-CloudMailbox
• Watch for serialization issues (everything's returned as a string)
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
How not to connect ..
Add-PSSnapin
Microsoft.Exchange.Management.PowerShell.E2010
 Unsupported
 Bypasses RBAC
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Objects and Properties
• Select returns (Exchange) properties
Get-Mailbox | Select Name
• To read (multivalue) properties
Get-Mailbox | Select Name, EmailAddresses
Get-Mailbox | Select Name –ExpandProperty EmailAddresses
Get-Mailbox | Select Name, @{n='EmailAddresses';
e={$_.EmailAddresses –join ","}}
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Filtering
• Get-Mailbox | Where {..}
– Where command processes result set = inefficient
• Get-Mailbox –Filter { .. }
– Filter early when possible (depends on cmdlet)
– Less data through pipe = efficient
– AD admins 
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Change multivalue properties
• To change a multivalue property
$addr= (Get-Mailbox User ).EmailAddresses
$addr+= 'new@contoso.com'
Set-Mailbox User - EmailAddresses $addr
• This is more efficient:
Set-Mailbox User –EmailAddresses
@{Add='new@contoso.com';Remove='old@contoso.com'}
• Only certain cmdlets, e.g. not Connector's IPranges
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Fan Out improves efficiency
• Fan Out distributes PowerShell commands
Get-TransportServer | Get-MessageTrackingLog
versus
Get-TransportServer | ForEach {
Invoke-Command -ConfigurationName Microsoft.Exchange
-ConnectionUri http://$($_.Name)/PowerShell
-ScriptBlock { Get-MessageTrackingLog }
–Authentication Kerberos}
• Complex or interactive ? => jobs / runspaces
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Check Permissions
• How to check permissions on Mailboxes
Get-Mailbox | Get-MailboxPermission
Get-Mailbox | Get-RecipientPermission
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Check Permissions
• Get more in detail
Get-Mailbox | Get-MailboxPermission
| Where { !$_.IsInherited –and
$_.User –notlike 'NT AUTHORITYSELF' –and
$_.AccessRights –eq 'FullAccess' }
Get-RecipientPermission | Where {
@('NT AUTHORITYSELF','NULL SID') -notcontains $_.Trustee}
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Date Math
• Get-Date
• (Get-Culture).DateTimeFormat
• Calculations
(Get-Date).AddDays(-7)
Get-Date (Get-Date).AddMonths(-1).ToString("yyyy/MM/01")
(Get-Date (Get-Date).ToString(“yyyy/MM/01”)).AddDays(-1)
• Use this for reporting, troubleshooting or scripting
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
-EventId Send | Where { $_.Sender –like '*@contoso.com'}
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
-EventId Send | Where { $_.Sender –like '*@contoso.com'} |
Group Sender
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
-EventId Send | Where { $_.Sender –like '*@contoso.com'} |
Group Sender | Select Name,@{n='Total';e={ ($_.Group |
Measure TotalBytes -Sum).Sum }}
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
-EventId Send | Where { $_.Sender –like '*@contoso.com'} |
Group Sender | Select Name,@{n='Total';e={ ($_.Group |
Measure TotalBytes -Sum).Sum }} | Sort Total –Desc
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Message Tracking
• How does this come together?
Get-MessageTrackingLog -Start (Get-Date).AddDays(-7)
-EventId Send | Where { $_.Sender –like '*@contoso.com'} |
Group Sender | Select Name,@{n='Total';e={ ($_.Group |
Measure TotalBytes -Sum).Sum }} | Sort Total –Desc |
Select –First 10
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
POWERSHELL SCRIPTING
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Who uses scripting now?
• Batchfiles
• Windows Scripting Host
• Kixtart
• PowerShell
• Other ..
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
• Arrays: , @()
• Quotes: "$var" –ne '$var'
• Escaping (`), e.g. "[`"n`"]"
• "$(expression)", e.g. "$($_.Property)"
• Aliases (? % gcm dir where ..)
• $Profile (~ *nix .profile)
• ResultSize 1000
• Out-GridView
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Regular Expressions
• Pattern matching / replacing
• -match & -replace
– Default case-insensitive
– Use explicit operator: -cmatch, -imatch, ..
– Returns $matches
• More control?
– [regexp]::match / [regexp]::replace
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Examples
$ip –match "d.d.d.d"
$ip –match "d{1,3}.d{1,3}.d{1,3}.d{1,3}"
$ip –match "(d{1,3}.){3}d{1,3}"
$email –match "[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]+"
"first last" -ireplace "([a-z]+)s([a-z]+)",'$2 $1'
• Library: http://www.regexlib.com
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Error Handling
• Terminating / Non-Terminating
– Control: -ErrorAction / $ErrorActionPreference
• Try {} Catch {} Finalize {}
Try {
Set-Mailbox Dave –MaxMessageSize 100MB –EA Stop
}
Catch {
Write-Error "Error: $($_.Exception.Message)"
}
Finally {
Write-Output "We're done".
}
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Cmdlet Extension Agents
• Since Ex2010 (N/A @ Edge)
Get-CmdletExtensionAgent | ft Name,Priority,Enabled
• Scripting Agent
Extend, modify or replace non-Get cmdlet functionality
Enable-CmdletExtensionAgent 'Scripting Agent'
• ScriptingAgentConfig.xml
Distribute @ All Exchange servers (script PushScriptingAgentConfig)
Safeguard (code injection)
Correct XML (case-sensitive tags, &=&amp; <=&lt; >=&gt; )
#devconnections
PushScriptingAgentConfig.ps1
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Scripting Agent ApiCalls
#devconnections
Provision
Default
Properties
•Default properties
•Not overwrite
values set by higher
prio agent
Update
Affected
IConfigurable
•Pre-validation
values
Validate
•Property Validation
•Return $null = OK
OnComplete
•Post-Processing
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Anatomy
#devconnections
<?xml version="1.0" encoding="utf-8" ?>
<Configuration version="1.0">
<Feature Name="MbxPostCfg" Cmdlets="New-Mailbox">
<ApiCall Name="OnComplete">
if($succeeded) {
$Name = $provisioningHandler.UserSpecifiedParameters[“Name"]
Set-CASMailbox –Identity $Name -ActiveSyncEnabled $false
}
</ApiCall>
</Feature>
</Configuration>
Label
Cmdlet(s)
When
Scriptblock
POWERSHELL TIPS & TRICKS FOR EXCHANGE
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Take aways
• Don't assume
– .. everything works / is available / etc.
– .. PowerShell is consistent
• Filter early to improve efficiency
• Test
– incl. stuff you d/l & copy/paste one-liners
– Use the WhatIf switch 
#devconnections
POWERSHELL TIPS & TRICKS FOR EXCHANGE
Links
• Cmdlet Extension Agents
– http://wp.me/pIJRx-vZ
– http://bit.ly/PushScriptingAgentConfig
• Extending ISE
– http://wp.me/pIJRx-Kr
• Fan-Out using jobs / runspaces
– http://bit.ly/ExRunspace
#devconnections
SESSION TITLE
#devconnections
Rate This Session Now!
Rate with Mobile App:
1. Select the session from the
Agenda or Speakers menus
2. Select the Actions tab
3. Click Rate Session
Rate Using Our Website:
1. Register at www.devconnections.com/logintoratesession
2. Go to www.devconnections.com/ratesession
3. Select this session from the list and rate it
Tell Us
What
You
Thought
of This
Session
Be Entered to
WINPrizes!

More Related Content

What's hot

(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014Amazon Web Services
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Adam Tomat
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4DEVCON
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015Manuel Bernhardt
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4DEVCON
 
High Performance RPC with Finagle
High Performance RPC with FinagleHigh Performance RPC with Finagle
High Performance RPC with FinagleSamir Bessalah
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLIAmazon Web Services
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCRKerry Buckley
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Riccardo Terrell
 
Syn504 unleashing the power of the net scaler policy and expressions engine...
Syn504   unleashing the power of the net scaler policy and expressions engine...Syn504   unleashing the power of the net scaler policy and expressions engine...
Syn504 unleashing the power of the net scaler policy and expressions engine...Henrik Johansson
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 

What's hot (20)

(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019
 
Deploying SharePoint @ Cloud
Deploying SharePoint @ CloudDeploying SharePoint @ Cloud
Deploying SharePoint @ Cloud
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Powershell Demo Presentation
Powershell Demo PresentationPowershell Demo Presentation
Powershell Demo Presentation
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
High Performance RPC with Finagle
High Performance RPC with FinagleHigh Performance RPC with Finagle
High Performance RPC with Finagle
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
 
Sbt for mere mortals
Sbt for mere mortalsSbt for mere mortals
Sbt for mere mortals
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Syn504 unleashing the power of the net scaler policy and expressions engine...
Syn504   unleashing the power of the net scaler policy and expressions engine...Syn504   unleashing the power of the net scaler policy and expressions engine...
Syn504 unleashing the power of the net scaler policy and expressions engine...
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 

Viewers also liked

O365con14 - powershell for exchange administrators
O365con14 - powershell for exchange administratorsO365con14 - powershell for exchange administrators
O365con14 - powershell for exchange administratorsNCCOMMS
 
the Stairway to PowerShell in Office365
the Stairway to PowerShell in Office365the Stairway to PowerShell in Office365
the Stairway to PowerShell in Office365Thorbjørn Værp
 
Collab365: PowerShell for Office 365
Collab365: PowerShell for Office 365Collab365: PowerShell for Office 365
Collab365: PowerShell for Office 365Vlad Catrinescu
 
Windows power shell and active directory
Windows power shell and active directoryWindows power shell and active directory
Windows power shell and active directoryDan Morrill
 
Using PowerShell for active directory management
Using PowerShell for active directory managementUsing PowerShell for active directory management
Using PowerShell for active directory managementRavikanth Chaganti
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functionsmikepfeiffer
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secretChris Conte
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingConcentrated Technology
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershellSalaudeen Rajack
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationJason Stangroome
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Thomas Lee
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionRob Dunn
 
Free tools for win server administration
Free tools for win server administrationFree tools for win server administration
Free tools for win server administrationConcentrated Technology
 

Viewers also liked (20)

O365con14 - powershell for exchange administrators
O365con14 - powershell for exchange administratorsO365con14 - powershell for exchange administrators
O365con14 - powershell for exchange administrators
 
the Stairway to PowerShell in Office365
the Stairway to PowerShell in Office365the Stairway to PowerShell in Office365
the Stairway to PowerShell in Office365
 
Collab365: PowerShell for Office 365
Collab365: PowerShell for Office 365Collab365: PowerShell for Office 365
Collab365: PowerShell for Office 365
 
Windows power shell and active directory
Windows power shell and active directoryWindows power shell and active directory
Windows power shell and active directory
 
Using PowerShell for active directory management
Using PowerShell for active directory managementUsing PowerShell for active directory management
Using PowerShell for active directory management
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
 
From VB Script to PowerShell
From VB Script to PowerShellFrom VB Script to PowerShell
From VB Script to PowerShell
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
 
PowerShell crashcourse
PowerShell crashcoursePowerShell crashcourse
PowerShell crashcourse
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
 
PowerShell 8tips
PowerShell 8tipsPowerShell 8tips
PowerShell 8tips
 
Meet Windows PowerShell
Meet Windows PowerShellMeet Windows PowerShell
Meet Windows PowerShell
 
Best free tools for w d a
Best free tools for w d aBest free tools for w d a
Best free tools for w d a
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
 
Managing SQLserver
Managing SQLserverManaging SQLserver
Managing SQLserver
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 session
 
Free tools for win server administration
Free tools for win server administrationFree tools for win server administration
Free tools for win server administration
 
PS scripting and modularization
PS scripting and modularizationPS scripting and modularization
PS scripting and modularization
 

Similar to PowerShell Tips & Tricks for Exchange

Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)ÇözümPARK
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebMikel Torres Ugarte
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015CiaranMcNulty
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
Test driven development (java script & mivascript)
Test driven development (java script & mivascript)Test driven development (java script & mivascript)
Test driven development (java script & mivascript)Miva
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017Matthew Beale
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Cloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud WorkflowCloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud WorkflowRightScale
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivitynklmish
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
O365Engage17 - Managing exchange online using power shell, tips &amp; tricks
O365Engage17 - Managing exchange online using power shell, tips &amp; tricksO365Engage17 - Managing exchange online using power shell, tips &amp; tricks
O365Engage17 - Managing exchange online using power shell, tips &amp; tricksNCCOMMS
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Scott Keck-Warren
 

Similar to PowerShell Tips & Tricks for Exchange (20)

Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Test driven development (java script & mivascript)
Test driven development (java script & mivascript)Test driven development (java script & mivascript)
Test driven development (java script & mivascript)
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Cloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud WorkflowCloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud Workflow
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
O365Engage17 - Managing exchange online using power shell, tips &amp; tricks
O365Engage17 - Managing exchange online using power shell, tips &amp; tricksO365Engage17 - Managing exchange online using power shell, tips &amp; tricks
O365Engage17 - Managing exchange online using power shell, tips &amp; tricks
 
Php summary
Php summaryPhp summary
Php summary
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)
 

More from Michel de Rooij

Managing Exchange Online using PowerShell, Tips & Tricks
Managing Exchange Online using PowerShell, Tips & TricksManaging Exchange Online using PowerShell, Tips & Tricks
Managing Exchange Online using PowerShell, Tips & TricksMichel de Rooij
 
Exchange 2016 & Office Online Server
Exchange 2016 & Office Online ServerExchange 2016 & Office Online Server
Exchange 2016 & Office Online ServerMichel de Rooij
 
Microsoft Exchange Conference (MEC) 2014 Highlights
Microsoft Exchange Conference (MEC) 2014 HighlightsMicrosoft Exchange Conference (MEC) 2014 Highlights
Microsoft Exchange Conference (MEC) 2014 HighlightsMichel de Rooij
 
20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De Rooij20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De RooijMichel de Rooij
 
Exchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorExchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorMichel de Rooij
 
Amazing Autodiscover(ies), Exchange 2007/2010 Autodiscover
Amazing Autodiscover(ies), Exchange 2007/2010 AutodiscoverAmazing Autodiscover(ies), Exchange 2007/2010 Autodiscover
Amazing Autodiscover(ies), Exchange 2007/2010 AutodiscoverMichel de Rooij
 

More from Michel de Rooij (6)

Managing Exchange Online using PowerShell, Tips & Tricks
Managing Exchange Online using PowerShell, Tips & TricksManaging Exchange Online using PowerShell, Tips & Tricks
Managing Exchange Online using PowerShell, Tips & Tricks
 
Exchange 2016 & Office Online Server
Exchange 2016 & Office Online ServerExchange 2016 & Office Online Server
Exchange 2016 & Office Online Server
 
Microsoft Exchange Conference (MEC) 2014 Highlights
Microsoft Exchange Conference (MEC) 2014 HighlightsMicrosoft Exchange Conference (MEC) 2014 Highlights
Microsoft Exchange Conference (MEC) 2014 Highlights
 
20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De Rooij20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De Rooij
 
Exchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorExchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 Administrator
 
Amazing Autodiscover(ies), Exchange 2007/2010 Autodiscover
Amazing Autodiscover(ies), Exchange 2007/2010 AutodiscoverAmazing Autodiscover(ies), Exchange 2007/2010 Autodiscover
Amazing Autodiscover(ies), Exchange 2007/2010 Autodiscover
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

PowerShell Tips & Tricks for Exchange

  • 1. PowerShell Tips & Tricks for Exchange #devconnections
  • 2. POWERSHELL TIPS & TRICKS FOR EXCHANGE Agenda • Introduction • Exchange & PowerShell • Tips & Tricks – PowerShell scripting – Cmdlet Extension Agents • Demo #devconnections
  • 3. POWERSHELL TIPS & TRICKS FOR EXCHANGE • Jaap Wesselius • Independent Consultant • Exchange MVP (8yrs) • jaap@wesselius.info • @jaapwess • www.jaapwesselius.com • Michel de Rooij • Consultant @ Conclusion FIT • Exchange MVP • michel@eightwone.com • @mderooij • www.eightwone.com • TheUCArchitects.com #devconnections
  • 4. POWERSHELL TIPS & TRICKS FOR EXCHANGE Introduction • Who attended Sigi Jagott’s session? • PowerShell is a command-line environment • First introduced for Windows 2003 – Codename ‘Monad’ • Exchange Management Shell is add-on for PowerShell #devconnections
  • 5. POWERSHELL TIPS & TRICKS FOR EXCHANGE Exchange & PowerShell • On-Premises – PowerShell 1.0 (EX2007) – PowerShell 2.0 (EX2010) – PowerShell 4.0 (EX2013) • Exchange Online – PowerShell 4.0 • Which version am I running? – $PSVersionTable #devconnections
  • 6. POWERSHELL TIPS & TRICKS FOR EXCHANGE PowerShell basics • Verbs and Nouns – Get-, Set-, New-, Enable-, Remove- – Mailbox, DistributionGroup, ExchangeServer etc. • Works with objects which are loaded in memory • Processed/Manipulated in Memory – This can be very inefficient when not properly executed! #devconnections
  • 7. POWERSHELL TIPS & TRICKS FOR EXCHANGE Connecting with PowerShell • Implicit Remoting $ExchSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.contoso.com/PowerShell -Authentication Kerberos Import-PSSession $ExchSession • EXO: Uri https://ps.outlook.com/powershell/, Basic auth & AllowRedirection • Use -Prefix to import cmdlets as Verb-PrefixNoun, e.g. Get-CloudMailbox • Watch for serialization issues (everything's returned as a string) #devconnections
  • 8. POWERSHELL TIPS & TRICKS FOR EXCHANGE How not to connect .. Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010  Unsupported  Bypasses RBAC #devconnections
  • 9. POWERSHELL TIPS & TRICKS FOR EXCHANGE Objects and Properties • Select returns (Exchange) properties Get-Mailbox | Select Name • To read (multivalue) properties Get-Mailbox | Select Name, EmailAddresses Get-Mailbox | Select Name –ExpandProperty EmailAddresses Get-Mailbox | Select Name, @{n='EmailAddresses'; e={$_.EmailAddresses –join ","}} #devconnections
  • 10. POWERSHELL TIPS & TRICKS FOR EXCHANGE Filtering • Get-Mailbox | Where {..} – Where command processes result set = inefficient • Get-Mailbox –Filter { .. } – Filter early when possible (depends on cmdlet) – Less data through pipe = efficient – AD admins  #devconnections
  • 11. POWERSHELL TIPS & TRICKS FOR EXCHANGE Change multivalue properties • To change a multivalue property $addr= (Get-Mailbox User ).EmailAddresses $addr+= 'new@contoso.com' Set-Mailbox User - EmailAddresses $addr • This is more efficient: Set-Mailbox User –EmailAddresses @{Add='new@contoso.com';Remove='old@contoso.com'} • Only certain cmdlets, e.g. not Connector's IPranges #devconnections
  • 12. POWERSHELL TIPS & TRICKS FOR EXCHANGE Fan Out improves efficiency • Fan Out distributes PowerShell commands Get-TransportServer | Get-MessageTrackingLog versus Get-TransportServer | ForEach { Invoke-Command -ConfigurationName Microsoft.Exchange -ConnectionUri http://$($_.Name)/PowerShell -ScriptBlock { Get-MessageTrackingLog } –Authentication Kerberos} • Complex or interactive ? => jobs / runspaces #devconnections
  • 13. POWERSHELL TIPS & TRICKS FOR EXCHANGE Check Permissions • How to check permissions on Mailboxes Get-Mailbox | Get-MailboxPermission Get-Mailbox | Get-RecipientPermission #devconnections
  • 14. POWERSHELL TIPS & TRICKS FOR EXCHANGE Check Permissions • Get more in detail Get-Mailbox | Get-MailboxPermission | Where { !$_.IsInherited –and $_.User –notlike 'NT AUTHORITYSELF' –and $_.AccessRights –eq 'FullAccess' } Get-RecipientPermission | Where { @('NT AUTHORITYSELF','NULL SID') -notcontains $_.Trustee} #devconnections
  • 15. POWERSHELL TIPS & TRICKS FOR EXCHANGE Date Math • Get-Date • (Get-Culture).DateTimeFormat • Calculations (Get-Date).AddDays(-7) Get-Date (Get-Date).AddMonths(-1).ToString("yyyy/MM/01") (Get-Date (Get-Date).ToString(“yyyy/MM/01”)).AddDays(-1) • Use this for reporting, troubleshooting or scripting #devconnections
  • 16. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) #devconnections
  • 17. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) -EventId Send | Where { $_.Sender –like '*@contoso.com'} #devconnections
  • 18. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) -EventId Send | Where { $_.Sender –like '*@contoso.com'} | Group Sender #devconnections
  • 19. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) -EventId Send | Where { $_.Sender –like '*@contoso.com'} | Group Sender | Select Name,@{n='Total';e={ ($_.Group | Measure TotalBytes -Sum).Sum }} #devconnections
  • 20. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) -EventId Send | Where { $_.Sender –like '*@contoso.com'} | Group Sender | Select Name,@{n='Total';e={ ($_.Group | Measure TotalBytes -Sum).Sum }} | Sort Total –Desc #devconnections
  • 21. POWERSHELL TIPS & TRICKS FOR EXCHANGE Message Tracking • How does this come together? Get-MessageTrackingLog -Start (Get-Date).AddDays(-7) -EventId Send | Where { $_.Sender –like '*@contoso.com'} | Group Sender | Select Name,@{n='Total';e={ ($_.Group | Measure TotalBytes -Sum).Sum }} | Sort Total –Desc | Select –First 10 #devconnections
  • 22. POWERSHELL TIPS & TRICKS FOR EXCHANGE #devconnections
  • 23. POWERSHELL TIPS & TRICKS FOR EXCHANGE POWERSHELL SCRIPTING #devconnections
  • 24. POWERSHELL TIPS & TRICKS FOR EXCHANGE Who uses scripting now? • Batchfiles • Windows Scripting Host • Kixtart • PowerShell • Other .. #devconnections
  • 25. POWERSHELL TIPS & TRICKS FOR EXCHANGE • Arrays: , @() • Quotes: "$var" –ne '$var' • Escaping (`), e.g. "[`"n`"]" • "$(expression)", e.g. "$($_.Property)" • Aliases (? % gcm dir where ..) • $Profile (~ *nix .profile) • ResultSize 1000 • Out-GridView #devconnections
  • 26. POWERSHELL TIPS & TRICKS FOR EXCHANGE Regular Expressions • Pattern matching / replacing • -match & -replace – Default case-insensitive – Use explicit operator: -cmatch, -imatch, .. – Returns $matches • More control? – [regexp]::match / [regexp]::replace #devconnections
  • 27. POWERSHELL TIPS & TRICKS FOR EXCHANGE Examples $ip –match "d.d.d.d" $ip –match "d{1,3}.d{1,3}.d{1,3}.d{1,3}" $ip –match "(d{1,3}.){3}d{1,3}" $email –match "[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]+" "first last" -ireplace "([a-z]+)s([a-z]+)",'$2 $1' • Library: http://www.regexlib.com #devconnections
  • 28. POWERSHELL TIPS & TRICKS FOR EXCHANGE Error Handling • Terminating / Non-Terminating – Control: -ErrorAction / $ErrorActionPreference • Try {} Catch {} Finalize {} Try { Set-Mailbox Dave –MaxMessageSize 100MB –EA Stop } Catch { Write-Error "Error: $($_.Exception.Message)" } Finally { Write-Output "We're done". } #devconnections
  • 29. POWERSHELL TIPS & TRICKS FOR EXCHANGE Cmdlet Extension Agents • Since Ex2010 (N/A @ Edge) Get-CmdletExtensionAgent | ft Name,Priority,Enabled • Scripting Agent Extend, modify or replace non-Get cmdlet functionality Enable-CmdletExtensionAgent 'Scripting Agent' • ScriptingAgentConfig.xml Distribute @ All Exchange servers (script PushScriptingAgentConfig) Safeguard (code injection) Correct XML (case-sensitive tags, &=&amp; <=&lt; >=&gt; ) #devconnections PushScriptingAgentConfig.ps1
  • 30. POWERSHELL TIPS & TRICKS FOR EXCHANGE Scripting Agent ApiCalls #devconnections Provision Default Properties •Default properties •Not overwrite values set by higher prio agent Update Affected IConfigurable •Pre-validation values Validate •Property Validation •Return $null = OK OnComplete •Post-Processing
  • 31. POWERSHELL TIPS & TRICKS FOR EXCHANGE Anatomy #devconnections <?xml version="1.0" encoding="utf-8" ?> <Configuration version="1.0"> <Feature Name="MbxPostCfg" Cmdlets="New-Mailbox"> <ApiCall Name="OnComplete"> if($succeeded) { $Name = $provisioningHandler.UserSpecifiedParameters[“Name"] Set-CASMailbox –Identity $Name -ActiveSyncEnabled $false } </ApiCall> </Feature> </Configuration> Label Cmdlet(s) When Scriptblock
  • 32. POWERSHELL TIPS & TRICKS FOR EXCHANGE #devconnections
  • 33. POWERSHELL TIPS & TRICKS FOR EXCHANGE Take aways • Don't assume – .. everything works / is available / etc. – .. PowerShell is consistent • Filter early to improve efficiency • Test – incl. stuff you d/l & copy/paste one-liners – Use the WhatIf switch  #devconnections
  • 34. POWERSHELL TIPS & TRICKS FOR EXCHANGE Links • Cmdlet Extension Agents – http://wp.me/pIJRx-vZ – http://bit.ly/PushScriptingAgentConfig • Extending ISE – http://wp.me/pIJRx-Kr • Fan-Out using jobs / runspaces – http://bit.ly/ExRunspace #devconnections
  • 35. SESSION TITLE #devconnections Rate This Session Now! Rate with Mobile App: 1. Select the session from the Agenda or Speakers menus 2. Select the Actions tab 3. Click Rate Session Rate Using Our Website: 1. Register at www.devconnections.com/logintoratesession 2. Go to www.devconnections.com/ratesession 3. Select this session from the list and rate it Tell Us What You Thought of This Session Be Entered to WINPrizes!