Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Exchange Powershell

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

### Connecting to the on-premises Exchange 2016 ###

$Credentials = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri


http://< Exchange 2016 Mailbox server FQDN>/PowerShell/ -Authentication Kerberos
-Credential $Credentials

Import-PSSession $Session

Remove-PSSession $Session

=============================================================
### Examples of Exchange Management Shell ###

get-excommand (Must run on the Exchange Server itself)


get-excommand | more (Must run on the Exchange Server itself)
get-excommand | Measure-Object (Must run on the Exchange Server itself)
get-command -Noun Mailbox
Get-Help Set-Mailbox
help Enable-Mailbox | more
help Enable-Mailbox -Examples | more
Get-Help Set-Mailbox -Examples
Get-Mailbox
Get-Mailbox -Identity Administrator
Get-Mailbox -Identity Administrator | Format-List
OR)
Get-Mailbox -Identity Administrator | FL
Get-Mailbox -Identity Administrator | Format-List *email*
get-mailbox -Identity Administrator | Format-Table *name*
get-mailbox -Identity Administrator | Set-Mailbox -CustomAttribute6 "tshoot.com"
Get-Mailbox -Identity Administrator | Format-List *CustomAttribute6*
Set-Mailbox -Identity Administrator -CustomAttribute1 Zagazig

=============================================================

### Move the database to new location ###


Move-DatabasePath -Identity "DB2" -EdbFilePath e:\db\"DB2.edb"

### Set a specific options to the database ###


Set-MailboxDatabase -Identity DB2 -DeletedItemRetention 20:00:00:00
-CircularLoggingEnabled $true -ProhibitSendQuota 2.2GB

Dismount-Database -Identity DB2


Mount-Database -Identity DB2

Get-MailboxDatabase
New-MailboxDatabase -Name DB5 -Server exchange.tshoot.com
=============================================================
### configure circular logging for a database ###
Set-MailboxDatabase DB2 -CircularLoggingEnabled $True
Set-MailboxDatabase DB2 -CircularLoggingEnabled $False
=============================================================
### Enable a user mailbox ###
Enable-Mailbox -Identity abeer -database DB2

### Enable all user mailboxes in sales OU ###


Get-User -OrganizationalUnit sales | Enable-Mailbox -Database DB2

### Create a mailbox for each user in the sales OU ###


Get-User -OrganizationalUnit sales | Where-Object{$_.recipienttype -eq "user"} |
Enable-Mailbox -Database DB4

=============================================================

### Public Folders ###

Get-PublicFolder -Recurse
Get-PublicFolder -Recurse | FL
New-PublicFolder -Name Department -Path \ -Mailbox PFDB
>> Where PFDB is the name of the public folder mailbox

=============================================================

### Offline Address Book (OAB) ###

Get-OfflineAddressBook
New-OfflineAddressBook -name "Sales OAB" -AddressLists "Sales_Department"
Get-OfflineAddressBook | FL Name,Schedule
Get-OfflineAddressBook "Sales OAB" | Update-OfflineAddressBook
Get-OfflineAddressBook "Sales OAB" | FL Name,Lasttouch*

=============================================================

### Address Book Policies ###

New-GlobalAddressList -name Research -RecipientFilter {{Department -eq "Research"}}


Update-GlobalAddressList -Identity Research
New-OfflineAddressBook -name "Research OAB" -AddressLists "Research"
New-AddressBookPolicy -Name ResearchPolicy -AddressLists Zag_Dep
-OfflineAddressBook "Research OAB" -GlobalAddressList Research -RoomList "All
Rooms"
Get-Mailbox -OrganizationalUnit HR | Set-Mailbox -AddressBookPolicy
"ResearchPolicy"

=============================================================

### Powershell Examples ###

get-excommand | Format-Wide -Column 3


Get-Help Get-Mailbox
Get-Help Get-Mailbox -Full (Full details)
Get-Help Get-Mailbox -Detailed (More detailed information)
Get-Help Get-Mailbox -Examples

### Create a mailbox for a new user ###

$Password = Read-Host "Enter $('Password') for new-mailbox" -AsSecureString


New-Mailbox -UserPrincipalName 'abeer@tshoot.com' -Alias 'abeer' -name 'abeer
hosni' -OrganizationalUnit Users -Password $Password -FirstName abeer -LastName
hosni -DisplayName 'abeer hosni' -ResetPasswordOnNextLogon $true
Get-Mailbox 'abeer hosni' | Format-List
Get-Mailbox 'abeer hosni' | Format-Table
Displayname,Alias,ServerName,Database,Office,HiddenFromAddressListsEnabled
-AutoSize
Set-User 'abeer hosni' -office 'HQ office' -Department IT
Set-Mailbox 'abeer hosni' -HiddenFromAddressListsEnabled $true

### Enable mailboxs for existing users in a specific department ###


Get-User -RecipientTypeDetails User -Filter {Department -eq 'HR'} | Enable-Mailbox

### Create a Distribution Group ###


New-DistributionGroup -name 'HR Distribution List' -DisplayName 'HR Distribution
List' -Alias HRGrp -OrganizationalUnit 'tshoot.com/sales'
Get-User -Filter {Department -eq 'IT'} | Add-DistributionGroupMember 'HR
Distribution List'
Get-DistributionGroupMember 'HR Distribution List' | Measure-Object

=============================================================
### Database Powershell Commands ###
Get-Command *-mailboxdatabase (Get a list of command that includes
mailboxdatabase)
New-MailboxDatabase -Server mail -name DB1
Get-MailboxDatabase DB1 | FL Name,ProhibitSendReceiveQuota
Get-MailboxDatabaseCopyStatus -Server mail
Set-MailboxDatabase DB1 -ProhibitSendReceiveQuota 20GB
Mount-Database DBA
Invoke-Command {Restart-Service MSExchangeIS -PassThru} -Comp mail

### Move Mailboxes to the newly created Database ###


Get-User -RecipientTypeDetails UserMailbox -Filter {Department -eq 'IT'} | New-
MoveRequest -TargetDatabase 'DB1'
Get-MoveRequest | Group status

=============================================================

### Creating multiple mailbox databases at the same time ###

"DB1","DB2" | % {
New-MailboxDatabase -Server mail -Name $_
Mount-Database $_
}
Invoke-Command {Restart-Service MSExchangeIS -PassThru} -Comp mail

============================================================

### The Replication Health of the Database Availability Group ###

Test-ReplicationHealth
Get-MailboxDatabaseCopyStatus -Server mail

Test-ServiceHealth

c:\Program Files\Microsoft\Exchange
Server\V15\Scripts\./CheckDatabaseRedundancy.ps1 -MailboxDatabaseName "DB1"
=============================================================

### Modify the receive Connector to accept unauthenticated mail ###

Set-ReceiveConnector 'mail\Default Frontend mail' -PermissionGroups Anonymous


Get-ReceiveConnector 'mail\Default Frontend mail' | Add-ADPermission -User 'NT
Authority\Anonymous logon' -ExtendedRights MS-Exch-SMTP-Accept-Any-Recipient
Send-MailMessage -SmtpServer 'mail.tshoot.com' -Port 25 -From 'abeer@tshoot.com'
-To 'noreply@ecst.com' -Subject 'Test' -Body 'This is a test message'
Get-Queue -Server mail
Get-Queue -Identity mail\Unreachable | Get-Message | FL
Get-Queue -Identity mail\Unreachable | Get-Message | Remove-Message -Confirm:$false
Get-EventLog -LogName Application -Newest 10 -ComputerName mail

=============================================================

### Configuring Client Connectivity Options ###

Get-MapiVirtualDirectory -Server mail


Set-MapiVirtualDirectory -Identity "mail\mapi <Default web site>" -InternalUrl
https://mail.tshoot.com -ExternalUrl https://mail.tshoot.com

=============================================================

### Configuring Office Online Server Integration ###

Get-OrganizationConfig | FL "WAC"
Set-OrganizationConfig -WACDiscoveryEndPoint
https://office.tshoot.com/hosting/discovery

=============================================================

### Managing Access for Mobile Devices ###

New-ActiveSyncDeviceAccessRule -Characteristic DeviceOS -QueryString "Android


3.0.0" -AccessLevel block

=============================================================

### Troubleshooting SMTP message Delivery ###

1- Using Exchange toolbox ... Queue Viewer


2- Using telnet
telnet mail 25
helo
mail from: abeer@tshoot.com
rcpt to: ahmed@tshoot.com
data
subject: hello
this is a test mesg
.
quit

3- Using Mail Flow ...Delivery Reports

=============================================================

### Configuring Transport Settings ###

Get-TransportConfig
Get-TransportConfig | FL *max*
Set-TransportConfig -MaxSendSize 20MB -MaxReceiveSize 20MB

Mail Flow ... Receive Connectors tab

=============================================================

### Configuring Accepted and Remote Domains ###

Get-RemoteDomain
New-RemoteDomain -Name ECST -DomainName ecst.com
Set-RemoteDomain ECST -AutoForwardEnabled $false -DeliveryReportEnabled $false
Remove-RemoteDomain ECST
=============================================================

### Configuring SMTP Send and Receive Connectors ###

New-SendConnector -Name "Send to Internet" -AddressSpaces * -SourceTransportServers


mail,mail2

=============================================================

### Configuring and using Transport Rules ###


Mail Flow ... Rules tab

=============================================================

### Configuring and using DLP policy ###

compliance management ... data loss prevention

=============================================================

### Configuring edge sync ###

New-EdgeSubscription -FileName "c:\file.xml" (On the Edge transport


server)
New-EdgeSubscription -FileData {[byte[]]$ (Get-Content -Path "c:\file.xml"
-Encoding Byte -ReadCount 0]} -Site "Default-First-Site-Name" (On the mail
server)

=============================================================

### Configuring antispam features ###

cd '.\Program Files\Microsoft\Exchange Server\V15\Scripts\'


.\install-AntispamAgents.ps1
Restart-Service MSExchangeTransport
Set-TransportConfig -InternalSMTPServers @{add= "192.168.1.110","192.168.1.120"}
Get-TransportAgent
Get-ContentFilterConfig | FL enabled
Add-ContentFilterPhrase -Influence BadWord -Phrase "Poker Results"
Add-ContentFilterPhrase -Influence GoodWord -Phrase "Report Documents"
Get-ContentFilterPhrase

=============================================================

### Connecting to Exchange online by using power shell ###

$Credentials = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri


https://outlook.office365.com/PowerShell-liveid/ -Authentication basic-Credential
$Credentials allowredirection

Import-PSSession $Session

Get-Mailbox
Get-DistributionGroup
=============================================================

### Managing Permissions ###

permissions ... admin roles


Set-User abeer -Title Admin

=============================================================

### Configuring audit logging ###


Get-AdminAuditLogConfig
Search-AdminAuditLog -Cmdlets Add-ADPermission
Set-Mailbox -Identity abeer -AuditDelegate sendas,sendonbelahf -AuditEnabled $true

=============================================================

install shema using Powershell by

selecting /domaincontroller:

You might also like