Sunday 20 October 2013

How to use Remote Exchange Management Shell

Exchange Server 2013 allows the option to access Exchange Management Shell from a computer that is not installed with Exchange Management Tools... below are the steps to connect to Exchange Management Shell 

$MyCredential = Get-Credential

$NewSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ExchServerName/PowerShell/ -Credential $MyCredential

Import-PSSession $NewSession

Monday 1 July 2013

How to take Delegates Report in Exchange 2010 and Exchange 2013

Use the below scripts to take the delegates report in Exchange Server 2010 and Exchange Server 2013
###########################################################################
# NAME: Delegates Report for Exchange Server 2010/2013
# AUTHOR:  Rajkumar
# VERSION HISTORY:1.0 7/1/2013 - Initial release
###########################################################################

$ErrorActionPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
$MailboxUsers = get-mailboxdatabase | get-mailbox  -resultsize Unlimited | sort displayname
$Output=@();
# Perform a set of actions against each mailbox - Loop
foreach ($user in $MailboxUsers)
{
$Name = $user.Alias
$OutputItem = New-Object Object;
$delegates = Get-MailboxCalendarsettings $name |where {$_.resourcedelegates -notlike “”}
$delegateNames = $delegates.ResourceDelegates | ForEach { $_.Name }
$delegateString = $delegateNames -Join ", "

# Get the desired Ouputs
$OutputItem | Add-Member NoteProperty Alias $user.alias;
$OutputItem | Add-Member NoteProperty "Display Name" $user.name;
$OutputItem | Add-Member NoteProperty "PrimarySMTPAddress" $user.PrimarySMTPAddress;
$OutputItem | Add-Member NoteProperty "Delegates" $DelegateString;
# Add the object to our array of output objects
    $Output += $OutputItem;
# Export the output as CSV File
$Output | Export-CSV -Path "C:\Mailboxreport.csv" -NoTypeInformation
$ToAddress = "Rajkumar.MCITP@Outlook.com"
$FromAddress = "ExchangeAdmin@DomainName.com"
$Body = "Please find the attached Delegates report for Company Name"
$attachments = "C:\Temp\DelegatesReport.csv"
send-mailmessage -to $ToAddress -from $FromAddress -subject "Delegates Reports" -smtpserver ServerName.Domain.local -attachments $attachments -body $body

How to Create a New Mailbox in Exchange 2013 using Shell Command

Below the shell command which can be used to create a Mailbox in Exchange Server 2010 and Exchange Server 2013
$password = Read-Host "Enter password" -AsSecureString
New-Mailbox -UserPrincipalName Name@DomainName.in -Alias AliasName -Database "Database Name" -Name 'Name' -OrganizationalUnit Users -Password $password -FirstName FirstName -LastName Last Name -DisplayName "Display Name" -ResetPasswordOnNextLogon $true

Sunday 30 June 2013

How to configure email forwarding using shell command

To configure the email forwarding on a Mailbox use the below shell command
Set-Mailbox -Identity "Mailbox Name" -ForwardingSMTPAddress "EmailAddress@DomainName.com"
Please note that, above shell command will forward all the emails to the Forwarding SMTP Address and no emails will deliver to concerned Mailbox To set the forwarding option to deliver the email to mailbox and to the forwarding SMTP address use the below shell command
Set-Mailbox -Identity "Mailbox Name" -ForwardingSMTPAddress "EmailAddress@DomainName.com" -DeliverToMailboxAndForward $True

How to restrict the Recipient Limits for a Mailbox using Shell Command

To restrict the recipient limits per mailbox use the below shell command
Set-Mailbox -Identity "Mailbox Name" -RecipientLimits 10
Before setting the limit, you can check the existing configuration using
Get-Mailbox -Identity "Mailbox Name" | FL Name, RecipientLimits

How to Hide a Mailbox from Address List

To hide a mailbox from Address List, use the below shell command
Set-Mailbox -Identity "Mailbox Name" -HideFromAddressListsEnabled $True
To disable the Hide from Address List option
Set-Mailbox -Identity "Mailbox Name" -HideFromAddressListsEnabled $False

Saturday 29 June 2013

How to change the Mailbox Password using shell command

To set a new password for a Mailbox
Set-Mailbox -Identity "Mailbox Name" -Password (ConvertTo-SecureString -String "NewPassword" -AsPlainText -Force)
and to reset the password on next logon
Set-Mailbox -Identity "Mailbox Name" -Password (ConvertTo-SecureString -String "NewPassword" -AsPlainText -Force) -ResetPasswordOnNextLogon $True

How to quickly view the Max Send and Receive Size of a Mailbox

Use the below shell command to quickly view the Max Send and Receive Size limits of a Mailbox
Get-Mailbox -Identity "Mailbox Name" | FL Name, Max*

How to Set Mailbox Size Limits using Shell Command

Setting Mailbox Size limits using Shell commands is a quick steps which you can do that by using the below shell command
Set-Mailbox -Identity "Mailbox Name" -UseDatabaseQuotaDefaults $false -IssueWarningQuota 102400 -ProhibitSendQuota 104800 -ProhitSendReceiveQuota  204800
Values entered above as a limit is in KB

You can use this shell command in Exchange Server 2010/2013 and Office 365

View Mailbox Quota Limit settings using Shell Command

Use the below shell command to view the Mailbox Quota limit settings
Get-Mailbox -Identity "Mailbox Name" | Fl Name, UseDatabaseQuotaDefaults
If the UseDatabaseQuotaDefaults parameter is set to True then the Mailbox limits settings are inherited from the Database level settings, if it is set to false the use the below the shell command to find the quotas
Get-Mailbox -Identity "Mailbox Name" | Fl Name, UseDatabaseQuotaDefaults, ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota
Above Commands can be used in Exchange 2010 Exchange Server 2013 and Office 365

How to view the Archive Mailbox Information using Shell Command

To view the details of a mailbox using shell command we will use the Get-Mailbox commandlet, but how to view the details of the Archive Mailbox properties?

Use the below shell command to view the Archive Mailbox properties in Exchange Server 2010 and Exchange Server 2013
Get-Mailbox -Idenity "Mailbox Name" -Archive | fl
To view the Remote Archive Mailbox information, use the below shell command
Get-Mailbox -Idenity "Mailbox@DomainName.com" -RemoteArchive | fl

How to find the installed version of Exchange 2010 and Exchange 2013

To find the Exchange Server Version, use the below shell command

Get-ExchangeServer | FT Name, *Version*
To find the roll up version number
GCM ExSetup | %{$_.FileVersionInfo}

Thursday 27 June 2013

How to find the list of users having full access permission on other Mailbox

You may get an request to inform who are all having full access permission on a Shared Mailbox, to find the list of users who are all having full access permission on other Mailbox in Exchange Server 2010 and Exchange Server 2013, use the below shell command
Get-MailboxPermission -Identity "Mailbox Name"| where { ($_.AccessRights -like "*FullAccess*") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF") } | Select User

Basic Mailbox Statistics Report for Exchange 2010 and Exchange 2013

Looking for a basic Mailbox Statistics Report for Exchange Server 2010 and Exchange Server 2013? Below is the shell command that you can use to get the Mailbox Statistics Report
Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics | Select Displayname, ServerName, DatabaseName,TotalItemsize,IsArchivedMailbox, StorageLimitStatus, MailboxGuid, LastloggedOnUserAccount, LastLOgonTime |Export-csv C:\temp\MailboxStats.csv
Using the above shell command will allow you to export the Mailbox Statistics details as a CSV file and the Output will looks as shown below


How to quickly find why the emails are in Queue using Shell Command

Get-Queue will inform the status of emails queues in Server, if you find some queues increasing in queue viewer and you want to quickly find the reason for the queue build up, you can use the below shell command
Get-Queue -Identity "ServerName\QueueName" | FL Identity, MessageCount, NextHopDomain, LastError, LastRetryTime, NextRetryTime
Queue viewer will show the output on why the emails are in queue, you can check the reason from the LASTERROR parameter Below a sample output of the above shell command. Above shell command can be used in Exchange Server 2010 and Exchange Server 2013

How to view the emails in Queue using Shell Command

To view the emails in Queue on both Exchange Server 2010 and Exchange Server 2013, use the below Exchange Management Shell command
Get-Queue -Server "Hub Transport Server Name"
and to view the emails in all the Hub Transport Servers
Get-TransportServer | Get-Queue
Get-Queue will give the basic details about the queue, Status, message counts in queue and the Next Hop to where it is awaiting to deliver the email.

How to check the Mailbox Database Copy status using Shell Command

Below shell command will help you to find the Mailbox Database Copy Status in Exchange Server 2010 and Exchange Server 2013

To check the Mailbox Database Copy status
Get-MailboxDatabaseCopyStatus -Server "Active Server Name"
Status shows all the Database are mounted, which indicates that this server holds the active copy and the passive copy will be in healthy status as shown below
Get-MailboxDatabaseCopyStatus -Server "Passive Server Name"
Above Status shows Healthy which indicate all the Passive Copies are in healthy status.

How to check Mailbox Databases are Mounted

Use the below shell commands to find whether all the mailbox Databases in Exchange Organization are mounted
Get-MailboxDatabase -ResultSize Unlimted -Status | FT Name, Mounted
How the Database mount status on the particular server
Get-MailboxDatabase -Server "Server Name" | FT Name, Mounted
How to find database mount status of a particular database
Get-MailboxDatabase "Database Name" | FT Name, Mounted
You can use the above shell commands in Exchange Server 2010 and Exchange Server 2013

Wednesday 26 June 2013

How to Assign Send As Permission using Shell Command

Below shell command will be used to provide Send As permission on other Mailbox in Exchange Server 2010 and Exchange Server 2013
Add-AdPermission -Identity "MailboxName" -User "User who needs Permission" -ExtendedRights Send-As -AccessRights "ReadProperty", "WriteProperty"

How to assign Full Access Permission using Shell Command

In this post we will discuss the details about how to give full access permission on a mailbox in Exchange Server 2010 and Exchange Server 2013

Use the below shell command to give Full Access Permission on a Mailbox
Add-MailboxPermission -Identity MailboxName -User "User Who Needs Permission" -AccessRights FullAccess

How to get the Mailbox Count in Exchange 2010 and Exchange 2013

Getting the total count on the mailbox is very easy using Exchange Management Shell Commands and below are few useful examples
How to get the Mailbox Count in a Database
(Get-Mailbox -ResultSize Unlimited -Database "Database Name").count
How to get the Mailbox count in a Server
(Get-Mailbox -ResultSize Unlimited -Server "Server Name").count
How to get the Mailbox Count from the whole organization
(Get-Mailbox -ResultSize Unlimited ).count
Ok, I got the total count, now are you searching for option on how to get the room mailbox count?
(Get-Mailbox -ResultSize Unlimited -filter (RecipientTypeDetails -Eq "RoomMailbox")).count
How to calculate the Mailbox count which includes the disabled mailboxes in the database
(Get-MailboxStatistics -Database "Database Name").count
Hope its useful for you. Leave your comments if any details required.

Tuesday 25 June 2013

Message Tracking using Exchange Management Shell

We can use the Get-MessageTrackingLog shell command to quickly find the status of sent\received email. Use the below shell command to search for the emails sent between two users within particular interval and the details will be exported into CSV file for review
Get-MessageTrackingLog -ResultSize unlimited -Sender “Sender@emailaddress.com” –Recipient “Recipient@emailaddress.com” -Start "MM/DD/YYYY 00:00:00" -End "MM/DD/YYYY 23:59:00"|Select Timestamp, EventId, Source, SourceContext, MessageID, MessageSubject, Sender,{$_.Recipients}, InternalMessageID, ClientIP, ClientHostName, ServerIp, ServerHostName, ConnectorID,{$_.RecipientStatus},TotalBytes,RecipientCount,RelatedRecipients,Reference, ReturnPath,Messageinfo | Export-CSV C:\MessageTrackingLog.csv
Inorder to search for the emails from the all the Transport Server in your Exchange Organization use the below shell command
Get-TransportServer | Get-MessageTrackingLog -ResultSize unlimited -Sender “Sender@emailaddress.com” –Recipient “Recipient@emailaddress.com” -Start "MM/DD/YYYY 00:00:00" -End "MM/DD/YYYY 23:59:00"|Select Timestamp, EventId, Source, SourceContext, MessageID, MessageSubject, Sender,{$_.Recipients}, InternalMessageID, ClientIP, ClientHostName, ServerIp, ServerHostName, ConnectorID,{$_.RecipientStatus},TotalBytes,RecipientCount,RelatedRecipients,Reference, ReturnPath,Messageinfo | Export-CSV C:\MessageTrackingLog.csv
We can use the above shell commands in Exchange Server 2010 and Exchange Server 2013

How to generate Mailbox Report on Exchange Server 2010 or 2013

Looking for a script which can generate a mailbox report on Exchange Server 2010 and Exchange Server 2013, this script will surely help you to generate a Mailbox report and the report will be send as email.
$ErrorActionPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
$ToAddress = "rajkumar.mcitp@outlook.com"
$FromAddress = "Reporting Email Address"
$Body = "Please find the attached Mailbox Stats report for MRC"
$MailboxUsers = Get-Mailbox  -Resultsize Unlimited | sort displayname
$Output=@();

foreach ($user in $MailboxUsers)
{
 $Name = $user.Alias
 $MBsize = Get-MailboxStatistics $Name 
 $archive = Get-Mailboxstatistics $name -archive
  
$Select = New-Object Object;
    
# Selecting information to the object

  $Select | Add-Member NoteProperty "Display Name" $user.name;
$Select | Add-Member NoteProperty Alias $user.alias;
$Select | Add-Member NoteProperty "Primary SMTP Address" $user.PrimarySMTPAddress;
$Select | Add-Member NoteProperty "Recipient Type" $user.recipienttypedetails;
$Select | Add-Member NoteProperty "Use DB Quota Defaults" $user.UseDatabaseQuotaDefaults;
$Select | Add-Member NoteProperty "Prohibit Send At" $user.ProhibitSendQuota:
$Select | Add-Member NoteProperty "Prohibit Send\Receive At" $user.ProhibitSendReceiveQuota;
$Select | Add-Member NoteProperty "Database" $MBsize.Database;
$Select | Add-Member NoteProperty "Server Name" $MBsize.ServerName;
$Select | Add-Member NoteProperty "Server Name" $MBsize.MailboxGuid;
$Select | Add-Member NoteProperty "Mailbox Size" $MBsize.TotalItemSize;
$Select | Add-Member NoteProperty "Item Count" $MBsize.ItemCount;
$Select | Add-Member NoteProperty "Last Accessed Time" $MBsize.LastLogonTime;
$Select | Add-Member NoteProperty "Last Logon Account" $MBsize.LastLoggedOnUserAccount;
$Select | Add-Member NoteProperty "Storage Limit Status" $MBsize.StorageLimitStatus;
$Select | Add-Member NoteProperty "Deleted Item Count" $MBsize.DeletedItemCount;
$Select | Add-Member NoteProperty "Use Database Quota Defaults" $user.WhenMailboxCreated;
          
# Add the object to our array of output objects
    $Output += $Select;
       
 }

$Output | Export-CSV -Path "C:\Mailboxreport.csv" -NoTypeInformation

$attachments = "C:\Mailboxreport.csv"
send-mailmessage -to $ToAddress -from $FromAddress -subject "Mailbox Reports" 
-smtpserver exchangeserver.chennai.com -attachments $attachments -body $body

How to Send email in Powershell

In this post we will see how to send email from PowerShell

Send-MailMessage is the new shell command which can be used to send emails from PowerShell command and below is the one liner command to send emails
Send-MailMessage -To rajkumar.mcitp@outlook.com -From ExchangeAdmin@DomainName.com -Subject "Subject Name" -SmtpServer servername.domainname.com
Below are the parameters available with Send-MailMessage

-To   "Rajkumar.Mcitp@outlook.com", "rajkumar.mcitp@yahoo.com"
-Subject "Subject of the Email"
-Body "Information that has to be displayed on the body of the email"
-SmtpServer smtpservername.domainname.com
-From ExchangeAdmin@domainname.com
-Attachments "C:\Scripts\Output.csv"
-Bcc Admin@domainname.com
-BodyAsHtml $True or $false
-Cc Admin1@domainname.com
-Credential Powershell Credential
-DeliveryNotificationOption  $true
-Encoding   Encoding Methods like ASCII, UTF8, UTF7, UTF32
-Port Port Number (25)
-Priority   Normal, High, and Low
-UseSsl $true or $false
Below Sample shows the format which includes all the available parameters
Send-MailMessage -To rajkumar.mcitp@outlook.com -From ExchangeAdmin@Chennai.com -Subject "Test Email" -SmtpServer "ExchangeServer@Chennai.com -Body "This is a Test Email" -Attachments "C:\Output.csv" -BodyAsHtml $True -Cc "admin1@chennai.com" -Bcc "Admin2@Chennai.com" -Port 25 -Prority High -UseSsl $false 
Note: Send-MailMessage only works when PowerShell Version 2.0 or later