o365con14 - powershell for exchange administrators

82

Upload: nccomms

Post on 09-May-2015

804 views

Category:

Technology


3 download

DESCRIPTION

European Office 365 Connect Session

TRANSCRIPT

Page 1: O365con14 - powershell for exchange administrators
Page 2: O365con14 - powershell for exchange administrators

PowerShell for Exchange Administrators

Dejan Foro CEO,

Exchangemaster GmbH

European Office 365 Connect Conference,

Haarlem, Netherlands 2.4.2014

Page 3: O365con14 - powershell for exchange administrators

Speaker introduction

• 21 years in IT of which last 16 as an Exchange specialist

• 6 Exchange generations (5.5, 2000, 2003, 2007, 2010, 2013)

• 3,2 million mailboxes

• Exchange User Group Europe - Founder

• 9x Microsoft MVP for Exchange

• Founder and CEO, Exchangemaster GmbH, Zurich, Switzerland

Page 4: O365con14 - powershell for exchange administrators

Agenda

• Introduction

• Setting you up for working with PowerShell

• PowerShell basics

• Using PowerShell examples in daily Exchange administration

Page 5: O365con14 - powershell for exchange administrators

Presentation download

• This presentation will be available for download from

www.exchangemaster.net

Page 6: O365con14 - powershell for exchange administrators

Setting you up for work with PowerShellTools, etc.

Page 7: O365con14 - powershell for exchange administrators

Get the proper Tools

http://www.idera.com/productssolutions/freetools/powershellplus

Page 8: O365con14 - powershell for exchange administrators

PowerShell Plus

• Advantages over built in PowerShell editor

• Advanced Editor

• Code you use everday at hand

• Script sharing with your colleauges

• Profiles

• Modules loading

• Different layouts

• Code signing

Page 9: O365con14 - powershell for exchange administrators
Page 10: O365con14 - powershell for exchange administrators
Page 11: O365con14 - powershell for exchange administrators
Page 12: O365con14 - powershell for exchange administrators
Page 13: O365con14 - powershell for exchange administrators
Page 14: O365con14 - powershell for exchange administrators
Page 15: O365con14 - powershell for exchange administrators
Page 16: O365con14 - powershell for exchange administrators
Page 17: O365con14 - powershell for exchange administrators
Page 18: O365con14 - powershell for exchange administrators
Page 19: O365con14 - powershell for exchange administrators

If you use other scripting languages in additionto Powershell -

Page 20: O365con14 - powershell for exchange administrators

PowerGUI

Page 21: O365con14 - powershell for exchange administrators

PowerGUI

Page 22: O365con14 - powershell for exchange administrators

PowerGUI

Page 23: O365con14 - powershell for exchange administrators

PowerGUI

Page 24: O365con14 - powershell for exchange administrators

Introduction to PowerShellABC of Exchange Administration with PowerShell

Page 25: O365con14 - powershell for exchange administrators

Introduction

• How it used to be ....

• Problems of Scripting in Windows enviroment

• Many things could be done through command line

• VBScript – programming knowledge required, knowledge of VB, WMI, WBEM, ADSI, object models

• security voulnearable

Page 26: O365con14 - powershell for exchange administrators

Introduction

• How it is today ...

• Scripting with PowerShell in Exchange

• Command line interface developed first, than GUI

• EVERYTHING can be done via command line

• Exchange managment GUI actually executes PowerShell commands and shows you the syntax

• Single line commands replace pages of VB code

• Symple syntax

• Better security – exectution of powershell scripts completely disabled by default, require scripts to be signed, etc.

Page 27: O365con14 - powershell for exchange administrators
Page 28: O365con14 - powershell for exchange administrators

Introduction

• Exchange Powershell – 500+ commands

Get-Excommand

• Don’t worry, you will be cool with approx. 20

Page 29: O365con14 - powershell for exchange administrators

Why are you going to love PowerShell

• Task example :

• Get a list of mailboxes and export into .csv file

Page 30: O365con14 - powershell for exchange administrators

Why you are going to love PowerShell• VBScript

Dim SWBemlocator

Dim objWMIService

Dim colItems

Dim objFSO

Dim objFile

strTitle="Mailbox Report"

strComputer = “MyServer"

UserName = ""

Password = ""

strLog="Report.csv"

Set objFSO=CreateObject("Scripting.FileSystemObject")

Set objFile=objFSO.CreateTextFile(strLog,True)

strQuery="Select * from Exchange_Mailbox"

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")

Set objWMIService = SWBemlocator.ConnectServer(strComputer,"\root\MicrosoftExchangeV2",UserName,Password)

Set colItems = objWMIService.ExecQuery(strQuery,,48)

For Each objItem In colItems

objFile.writeline objItem.ServerName & "," &objItem.StorageGroupName &_

"," & objItem.StoreName & "," & Chr(34) & objItem.MailboxDisplayName

Next

objFile.close

Page 31: O365con14 - powershell for exchange administrators

Why you are going to love PowerShell

• PowerShell

Get-mailbox | export-csv c:\report.csv

Page 32: O365con14 - powershell for exchange administrators

.... And Action !!!

Page 33: O365con14 - powershell for exchange administrators

Command Syntax

• New-Mailbox

• Get-Mailbox

• Set-Mailbox

• Move-Mailbox

• Remove-Mailbox ...

Page 34: O365con14 - powershell for exchange administrators

Getting help

• List of all available PowerShell commands

Get-Command

• List of only Exchange commands

Get-Excommand

• Getting help about specific command

Get-Help Get-Mailbox

Get-Help Get-Mailbox – detailed

Get-Help Get-Mailbox – full

Page 35: O365con14 - powershell for exchange administrators

Getting info about users/mailboxes

• List of all mailboxes in organisation

Get-Mailbox

Get-Mailbox -ResultSize unlimited

Page 36: O365con14 - powershell for exchange administrators

Getting all available properties

Get-Mailbox | Format-List

Get-Mailbox –ResultSize 1 | Format-List

Page 37: O365con14 - powershell for exchange administrators

Getting just a list of properties names

Get-Mailbox | Get-Member -MemberType *Property |

Select-Object Name

Page 38: O365con14 - powershell for exchange administrators

Selecting & SortingGet-Mailbox | Select-Object -Property DisplayName, PrimarySMTPAddress

Get-Mailbox | Select-Object -Property DisplayName,

PrimarySMTPAddress | Sort-Object -Property DisplayName

Page 39: O365con14 - powershell for exchange administrators

Examples

• List all mailboxes, sort by name, and export into a CSV file

Get-Mailbox | Sort-Object -Property Name |

Export-csv c:\mailboxes.csv

• Get a list of mailboxes from Active Directory OU named Users

Get-Mailbox -OrganizationalUnit Users

Page 40: O365con14 - powershell for exchange administrators

Examples• Count mailboxes in organisation

(Get-mailbox).count

• Getting all properties for a specific user

Get-Mailbox | where {$_.DisplayName -eq "Dejan Foro"} |

format-list

• Who is the postmaster ?

Get-Mailbox | where {$_.EmailAddresses -contains

"[email protected]"}

Page 41: O365con14 - powershell for exchange administrators

Examples

• Who is the user with GUID e65a6ff3-d193-4563-9a8e-26a22315a686 ?

Get-Mailbox | where {$_.guid -eq "e65a6ff3-d193-

4563-9a8e-26a22315a686"}

• Who has UM extention 200 ?

Get-Mailbox | where {$_.extensions -contains "200"}

Page 42: O365con14 - powershell for exchange administrators

Getting info about servers

• Give me a list of Exchange servers

Get-Exchangeserver

Get-ExchangeServer | Select-Object -Property Name, Edition,

AdminDisplayVersion, ServerRole | format-list

Page 43: O365con14 - powershell for exchange administrators

Examples

• Give me a list of mailbox servers

Get-ExchangeServer | where {$_.ServerRole -ilike "*Mailbox*"}

• Do we have servers running on trial version of Exchange and if yes when do they expire ?

Get-ExchangeServer | where {$_.IsExchange2007TrialEdition -eq "True"} | Select-

Object -Property FQDN, RemainingTrialPeriod

Page 44: O365con14 - powershell for exchange administrators

Getting membership of a group

Get-DistributionGroupMember -identity "Swiss IT Pro User Group Moderators"

Page 45: O365con14 - powershell for exchange administrators

Managing the user lifecycle

• Creating users - Importing from a .csv file

• Modifing users – move to another database

• Removing mailboxes and users

Page 46: O365con14 - powershell for exchange administrators

Importing users from a .CSV file

• Task

• Import users from a file c:\users.csv

• For every user

• Create user account in AD of form [email protected]

• Put them in Organizational Unit VIP

• Create a mailbox in database “Standard users”

• Enter his first and last name

• Set all users with password Password123 and require the users to change the password at first logon

Page 47: O365con14 - powershell for exchange administrators

Importing users from a .CSV file

Import-CSV c:\users.csv

Page 48: O365con14 - powershell for exchange administrators

Procesing values from a csv file

• Processing each row of data from .CSV file

Import-CSV c:\users.csv | ForEach-Object { SOME ACTION}

• Command for creating Users

New-Mailbox

Get-Help New-Mailbox –full

Page 49: O365con14 - powershell for exchange administrators

Processing values from .CSV file

• Referencing column names from the .CSV file

$_.columnname

• Converting Password text into secure string

$Password = ConvertTo-SecureString -String "Password123" -

asplaintext -force

Page 50: O365con14 - powershell for exchange administrators

Importing users from a .CSV file

• Putted all together

$Password = ConvertTo-SecureString -String "Password123" -asplaintext -force

Import-Csv c:\users.csv | ForEach-Object {

$Name = $_.First + " " + $_.Last

$UPN = $_.First + "." + $_.Last + "@exchangemaster.net"

New-Mailbox -Name $Name -UserPrincipalName $UPN -Password $Password -

OrganizationalUnit VIP -Database 'standard users' -FirstName $_.First -LastName

$_Last -ResetPasswordOnNextLogon $True}

Page 51: O365con14 - powershell for exchange administrators

Making changes to users

• Apply policies

• Assing to groups

• Enable or disable features

• Changing attributes

• Moving mailboxes ....

Page 52: O365con14 - powershell for exchange administrators

Moving mailboxes

• Moving mailoboxes of users in OU VIP to a new database for VIPs

Get-Mailbox -OrganizationalUnit "VIP" | Move-Mailbox -

TargetDatabase "VIP users"

Page 53: O365con14 - powershell for exchange administrators

Moving mailboxes

• Checking for mailbox location after move

Get-Mailbox | Select-Object Name,Database

Page 54: O365con14 - powershell for exchange administrators

Removing mailboxes

• Check before deleting !

Get-Mailbox -OrganizationalUnit VIP | Remove-Mailbox -WhatIf

• Remove them

Get-Mailbox -OrganizationalUnit VIP | Remove-Mailbox

Page 55: O365con14 - powershell for exchange administrators

Recommendation

• 3rd party snap-in for better manipulation of ADobjects

• Quest Software

• ActiveRoles Management Shell for Active Directoy

Page 56: O365con14 - powershell for exchange administrators

Managing queues

• Removing spam messages from the queue

Remove-Message -Filter {FromAddress -like "*spammer.com*“ } -

withNDR $false

Page 57: O365con14 - powershell for exchange administrators

Testing

• Get a list of test commands

• Get-Command test*

Page 58: O365con14 - powershell for exchange administrators

Testing

Page 59: O365con14 - powershell for exchange administrators

Communicating with user from the script

• Prompting user

Write-Host -ForegroundColor red -BackgroundColor yellow

"Formating your drive c: ..."

Write-Host -ForegroundColor blue -BackgroundColor green "Be

cool I am just kidding"

• Getting user input

Read-Host

Page 60: O365con14 - powershell for exchange administrators

Script samplesUsing PowerShell in your daily Exchange admin routine

Page 61: O365con14 - powershell for exchange administrators

Install Exchange 2013 pre-requisites

http://technet.microsoft.com/en-us/library/bb691354(v=exchg.150).aspx#WS2008R2SP1MBX

Import-Module ServerManager

Add-WindowsFeature Desktop-Experience, NET-Framework, NET-HTTP-Activation,

RPC-over-HTTP-proxy, RSAT-Clustering, RSAT-Web-Server, WAS-Process-Model,

Web-Asp-Net, Web-Basic-Auth, Web-Client-Auth, Web-Digest-Auth, Web-Dir-Browsing,

Web-Dyn-Compression, Web-Http-Errors, Web-Http-Logging, Web-Http-Redirect,

Web-Http-Tracing, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Lgcy-Mgmt-Console,

Web-Metabase, Web-Mgmt-Console, Web-Mgmt-Service, Web-Net-Ext, Web-Request-Monitor,

Web-Server, Web-Stat-Compression, Web-Static-Content, Web-Windows-Auth, Web-WMI

Page 62: O365con14 - powershell for exchange administrators

Good Morning Exchange

FAQ 000116 - Good Morning Exchange - doing a quick check on Exchange using PowerShellhttp://www.exchangemaster.net/index.php?option=com_content&task=view&id=247&Itemid=1&lang=en

It checks the following 3 things on all your Exchange machines:- Are Exchange services running?- Are all databases mounted and healty?- Are E-mails piling up in the queues?

Page 63: O365con14 - powershell for exchange administrators

Good Morning Exchnage

Checking services...

All Exchange services OK

Checking databases..

All Databases OK

Checking Queues...

All Queues OK

All systems OK, you can have your morning coffee :)

|---|

| |)

|___|

Page 64: O365con14 - powershell for exchange administrators

Checking services...

All Exchange services OK

Checking databases..

All Databases OK

Checking Queues...

SERVER01

SERVER01\1448 500

SERVER01\1478 300

SERVER01\1485 50

Sorry mate, no coffee for you. There is work to do.

|---|

| |)

|___|

Good Morning Exchnage

Page 66: O365con14 - powershell for exchange administrators

Did the backup run last night ?

Backup Status Report for All Databases in Exchange Organization MAIL

Created on 23.09.2013 15:40:57

Backup Status of Mailbox Databases

Server Name BackupInProgress LastFullBackup LastIncrementalBackup LastDifferentialBackup LastCopyBackup RetainDeletedItemsUntilBackup

-------- ---- ---------------- -------------- --------------------- ---------------------- -------------- -----------------------------

SERVER01 DB01 False 20.09.2013 17:01:35 False

SERVER01 DB02 False 20.09.2013 17:01:35 23.07.2013 18:37:31 False

SERVER02 DB03 False 20.09.2013 17:01:35 23.07.2013 20:19:37 False

SERVER02 DB04 False 20.09.2013 17:01:35 23.07.2013 21:49:31 False

SERVER03 DB05 False 22.09.2013 17:20:02 23.09.2013 12:05:12 False

SERVER03 DB06 False 22.09.2013 17:20:03 23.09.2013 12:05:12 False

SERVER03 DB09 False 22.09.2013 17:20:02 23.09.2013 12:05:12 False

SERVER04 DB07 False 22.09.2013 17:20:03 23.09.2013 12:05:12 False

SERVER04 DB08 False 22.09.2013 17:20:02 23.09.2013 12:05:12 False

Backup Status of Public Folder Databases

Server Name BackupInProgess LastFullBackup LastIncrementalBackup LastDifferentialBackup LastCopyBackup RetainDeletedItemsUntilBackup

-------- ---- --------------- -------------- --------------------- ---------------------- -------------- -----------------------------

SERVER01 Public Folder DB06 22.09.2013 17:20:03 False

SERVER03 Public Folder DB08 20.09.2013 17:01:35 False

Page 67: O365con14 - powershell for exchange administrators

DAG Maintenance

• Scripts that come with Exchange server

C:\Program Files\Microsoft\ExchangeServer\V14\scripts

StartDagServerMaintenance.ps1

StopDagServerMaintenance.ps1

RedistributeActiveDatabases.ps1

Page 68: O365con14 - powershell for exchange administrators

DAG Maintenance

Exchange01 Exchange02

DAG01

DB01

DB02

DB03

DB04

DB01

DB02

DB03

DB04

Page 69: O365con14 - powershell for exchange administrators

DAG MaintenanceOn the first node1) execute

.\StartDagServerMaintenance.ps1 -ServerName Exchange01

2) Do your maintenance (patching, whatever) on the first node

Exchange01 Exchange02

DAG01

DB01

DB02

DB03

DB04

DB01

DB02

DB03

DB04

Page 70: O365con14 - powershell for exchange administrators

DAG Maintenance

3) After maintenance is completed

.\StopDagServerMaintenance.ps1 -ServerName Exchange01

Exchange01 Exchange02

DAG01

DB01

DB02

DB03

DB04

DB01

DB02

DB03

DB04

Page 71: O365con14 - powershell for exchange administrators

DAG Maintenance4) On the second node

.\StartDagServerMaintenance.ps1 -ServerName Exchange02

5)Do the patching

Exchange01 Exchange02

DAG01

DB01

DB02

DB03

DB04

DB01

DB02

DB03

DB04

Page 72: O365con14 - powershell for exchange administrators

DAG Maintenance

6) On the second node

.\StopDagServerMaintenance.ps1 -ServerName Exchange02

Page 73: O365con14 - powershell for exchange administrators

DAG Maintenance

7) execute

.\RedistributeActiveDatabases.ps1 -DagName DAG01 -BalanceDbsByActivationPreference-ShowFinalDatabaseDistribution -Confirm:$false

Page 74: O365con14 - powershell for exchange administrators

Compare Services

• Computer1: SERVER01

• Computer2: SERVER02

• SystemName DisplayName StartMode State Status

• ---------- ----------- --------- ----- ------

• SERVER01 Application Management Manual Running OK

• SERVER02 Application Management Manual Stopped OK

• SERVER01 PsKill Manual Stopped OK

• SERVER01 WinHTTP Web Proxy Auto-Discovery Service Manual Running OK

• SERVER02 WinHTTP Web Proxy Auto-Discovery Service Manual Stopped OK

Page 78: O365con14 - powershell for exchange administrators

Powershell Books – Advanced

Page 79: O365con14 - powershell for exchange administrators

Q&A

• Q&A session 17:30 – 18:30

• You can send your questions in advance to

[email protected]

Page 80: O365con14 - powershell for exchange administrators

Contact

Dejan Foro, CEO

[email protected]

Exchangemaster GmbH

www.exchangemaster.net

Page 81: O365con14 - powershell for exchange administrators

Show your scripts to the world

• Technet Gallery

• Powershell.com

Page 82: O365con14 - powershell for exchange administrators