Showing posts with label exchange. Show all posts
Showing posts with label exchange. Show all posts

How to monitor Exchange Queues?

How to monitor Exchange Queues?

How to monitor Exchange Queues / How to setup an Alert for Exchange Queues...


#Author : Nishant Naidu

#Technet - i-TechNinja

# https://social.technet.microsoft.com/profile/i-tech%20ninja/
#https://itechninja.blogspot.in/
#https://crazycerebro.blogspot.in
#https://social.technet.microsoft.com/wiki/contents/articles/47620.how-to-monitor-exchange-queues-how-to-setup-an-alert-for-exchange-queues.aspx

#load Snapin
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

#Set Mailing parameters
$sendMailMessageParams = @{
    Smtpserver = " smtp server "
    To         = " To? "
    From       = " From? "
}


# HTML Body 
$head = "<style>",
        "BODY { background-color: white; }",
        "TABLE { border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse; }",
        "TH { border-width: 1px; padding: 5px; border-style: solid; border-color: black; foreground-color: black; background-color: LightBlue}",
        "TD { border-width: 1px; padding: 5px; border-style: solid; border-color: black; foreground-color: black; background-color: white}",
        "</style>" | Out-String
 #Logic to setup
if ($Queue = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | Get-Queue | Where-Object { $_.MessageCount -gt 200 } | Select Identity, DeliveryType, NextHopDomain, RiskLevel, MessageCount, Status, Velocity) {  $body = $Queue | ConvertTo-Html -Head $head | Out-String
#Invoke     
Send-MailMessage -Subject "Exchange Queue Alerts-Threshold 200" -Priority High -Body $body -BodyAsHtml @sendMailMessageParams
}
else{
    Send-MailMessage -Subject "Exchange Queue Alerts-Threshold 200" -Body "Queues are below Threshold limit - 200 "-BodyAsHtml @sendMailMessageParams
}

How to Use?

1. Save this file as .ps1 wherever with whatever name you want to.
2. Open Task Scheduler
3. Create a New task and set the task occurrence for this .ps1 file.

Thank You.
For any query, please comment down below.

#You can make use of BuyNow button for Donation purpose 

How to write a Formatted Email using Powershell / Automation

How to write a Formatted Email using Powershell / Automation

How to write a Formatted Email using Powershell / Automation


Hi Cerebros,

This script will help you to write a formatted email using Powershell :)

With the help of this script, you can send mail with customize date.

You can also have a formatted custom body, html, table, cells and all.

You can automate or schedule this to run occasionally.

When you are sending static mails every time across number of users, you can simply use this script to do your job.

Let the script do its job and you sit back and relax :enjoy your day :)

ThisScript :

# Hi, This script will help you to format mail
# You can use this to automate/schedule mail
# You can also convert this ps1 to exe and schedule it
# I hope it helps :)

#If you want to sent attachment in mail pls mention filename path below
$dir = "c:\crazycerebro\yourfilename.here"


#If you to add dynamic date so that whenever you schedule it should take that particular date
$titleDate = get-date -uformat "%m-%d-%Y - %A"

#here goes our code :)



$smtpsettings = @{

BodyAsHtml = $true

To =  "sender@email.id"

cc = "ifyouwantocopy@anyone.id" 

From = "mailveliveryfrom@id"

Subject = "Your subject here $titledate"

SmtpServer = "Your smtp server name here"

Body = " 

Hi Team,<br>

 <br></br>

This is first line of the body.</br>

<br></br>

<br>This is second line of the body.</br>

<br></br>

<br><b>This is third line of the body.</b></br>



<br></br><br></br>

<style>

table, th, td, tr {

    border: 1px solid black;

    border-collapse: collapse;

}

th, td, tr {

    padding: 5px;

    text-align: left;

}

</style>

<table>

  <caption><b>Table Heading</b></caption>

  <tr>

    <th bgcolor='#CDD1F9'>Column Name1</th>

    <th bgcolor='#CDD1F9'>Column Name2</th>

  <th  bgcolor='#CDD1F9'>  Column Name3 </th>

  </tr>

  <tr>

    <td>Col Value1</td>

    <td>Col value2</td>

    <td>Col Value3</td>

  </tr>

</table>

<br></br><br></br><br></br>

<br> <b> This is  Auto generated mail follow - crazycerebro.blogspot.com</b></br>"



   Attachments = $dir

}

 Send-MailMessage @smtpsettings 

#Here you are done :)

  #Thanks Everyone, i hope you like this script

  #Please comment in the blog if you have any query

 #If you want to make a custom script for you please comment down below I will try my best :)

  Thanks Guys, Comment down below if you have any query :)

How to Detect Who Accessed Another User’s Mailbox

How to Detect Who Accessed Another User’s Mailbox


Using shared mailboxes in Office 365 can facilitate communication in team projects. However, giving multiple users access permissions for the same mailbox increases the risk of security incidents and leaks of sensitive data. Non-owners with access rights can, unintentionally or maliciously, forward a message, move an e-mail with sensitive content to another location, or — even worse — delete something important from an Exchange Online shared mailbox.

1. Open PowerShell -> Run the following command to connect with Exchange Online instance and enter your credentials in the pop-up window:

 2. To enable mailbox auditing run:
  • For a single mailbox:


  • For all mailboxes:

  • To check what mailboxes have auditing enabled run:

 Open Exchange Administration Center -> Navigate to “Compliance Management” Auditing.
4. Click “Run a non-owner mailbox access report”. You will get the report on non-owner access to all mailboxes with enabled auditing over the past two weeks.
5. To view non-owner access to a specific mailbox Click on a mailbox to view all non-owner access events with the details.





5 Free Exchange Security Tools You Probably Don’t Know About

Exchange email security is a huge front to defend. There are now so many attack surfaces that it can be hard to decide how to start. Here are a few things that you might want to consider when thinking about your Exchange infrastructure security setup.

This is by no means a full list.

1. Full Access and Send As Permissions

A brilliant feature of Exchange is the ability to grant users access to others’ mailboxes. You can do this in two ways, either by using the “Full Access” permission, which effectively gives them the same rights as the owner of the mailbox, or by granting “Send As,” which just gives them the permissions to change the “from” field to a specified user.
To grant full access, you can use a PowerShell command like the following:
Get-Mailbox “MailboxToView” | Add-ADPermission -User “PersonWhoNeedsPermission” -ExtendedRights “Full Access”

Be aware that in Exchange 2013 and later, any member of ‘Domain Admins’ cannot view other users’ mailboxes.
To list users who have access, you can run the following PowerShell command:
Get-Mailbox | Get-MailboxPermission | Where { $_.AccessRights -eq “FullAccess” -and $_.User.ToString() -ne “NT AUTHORITY\SYSTEM” -and $_.User.ToString() -ne “NT AUTHORITY\SELF”} | Select Identity, User | fl


This will give you a list of mailboxes with users and groups that are able to access them.
Note: this may take a while to run across many mailboxes!

2. Transport Rules

One of the most commonly overlooked Exchange security points is the humble transport rule. If you have a malicious administrator, they can potentially view everyone’s email just by setting up a transport rule.
I know of an organization where someone had modified the default signature transport rule to blind carbon themselves on every single email that left the company. It was only by chance when another sysadmin was asked to modify the signature that they noticed this.
This kind of behaviour is quite hard to detect, but a simple PowerShell command would have revealed this:
Get-TransportRule | Where {$_.BlindCopyTo -ne $null} | fl Name, BlindCopyTo


Other actions that could potentially be used for malicious purposes are as follows:
Get-TransportRule | Where {$_.ModerateMessageByUser -ne $null} | fl Name, ModerateMessageByUser
This command will list any rules where approval is needed before the message is delivered.
Get-TransportRule | Where {$_.DeleteMessage -eq $true} | fl Name
This command will list any rules that simply delete the message.

3. Exchange Roles

Microsoft has used the Role-Based Access Control model (RBAC) since Exchange 2010, and it became more prominent in Exchange 2013 and later. In essence, you assign users and groups permissions to perform actions and tasks using the “who, what, where” method.
As an example, let’s take a branch manager of ExampleCo’s London office (who). Management want the branch manager to be able to change the out-of-office replies (what) for their branch (where).
Exchange role security allows us to do this by creating a custom role group:
New-RoleGroup -Name ExampleCo_London -Roles (See Later) -Members BranchMgr1
This will create a role group with no scope applied – no “where,” i.e., BranchMgr1 will be able to use their permissions on all Exchange objects that support it.
We can limit the scope to a single organizational unit by omitting -Members and supplying -RecipientOrganizationalUnitScope instead:
New-RoleGroup -Name ExampleCo_London -Roles (See Later) -RecipientOrganizationalUnitScope “LondonOU”
In order to achieve our goal of allowing BranchMgr1 to change the out-of-office replies, we can assign them the “Help Desk” built-in role:
New-RoleGroup -Name ExampleCo_London -Roles “Help Desk”
You can also create your own roles with a custom set of permissions.
We had a situation recently where we needed to find out who had changed a transport rule on one of our Exchange servers; luckily, there is an easy PowerShell command to view who has permissions to change a mailbox or server:
Get-ManagementRoleAssignment -Role “Transport Rules” -WritableServer Exchange -GetEffectiveUsers
Running this on our environment yielded a list of groups who could perform this task:

4. Exchange Edge Servers

I cannot stress enough how important it is to have an Exchange Edge server. These are highly cut-down servers that just expose port 25 (SMTP) to the outside world. This narrows their attack surface dramatically and offloads spam and anti-virus processing to another (virtual) server.
Edge servers are not members of your active directory domain, so as long as you’re not sharing passwords between admin accounts (you’re not, are you?), then an attacker who manages to get control of your Edge Server doesn’t really have much of a foothold.
Required information from Active Directory that is used for early recipient rejection for example, is sent via a one-way Edge Sync process.

5. Hybrid Configurations

I’ll finish by just drawing your attention to Office 365 and Hybrid configurations. It is possible to apply most of the on-premise configurations to the cloud or hybrid part of your Exchange configuration.
You can use the following command to establish a connection to the Exchange Online servers:
$creds = Get-Credential
 $eonlinesession = New-PSSession – ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $creds -Authentication Basic -AllowRedirection
 Import-PsSession $eonlinesession
Check that you’ve connected successfully by issuing something like get-mailbox and see if it returns mailboxes that you know are offsite.
Once you’re done, don’t forget to disconnect; otherwise, you can run into issues later on in which you use up all of the available PowerShell sessions for your user (you then have to wait for them to timeout, which is not fun.).
Remove-PsSession $eonlinesession






3 Common Problems in Migrating to Exchange 2016

3 Common Problems in Migrating to Exchange 2016
3 Common Problems in Migrating to Exchange 2016


As support for Exchange 2010 wanes and the bell is tolling for Exchange Server 2007’s useful life, a lot of organizations are taking a look at moving to Exchange Server 2016. The three most common showstoppers for Exchange migration are namespace issues, version control, and certificate problems. Let’s take a look at how to deal with each of them.

1. Namespace issues

The migration to Exchange 2016 presents a great opportunity to consolidate some of the namespaces your company is using—that is, the domain names that you currently have in place for your users to access Exchange via Outlook’s remote procedure call (RPC) over HTTP functionality, Outlook Web App (OWA), the Exchange Control Panel, connections for smartphones, tablets, and newer versions of Outlook through ActiveSync, apps and extensions that interface with Exchange through Exchange Web Services (EWS), the Offline Address Book (OAB), and the Autodiscover service that helps clients automatically connect to Exchange without a bunch of confusing configuration information being required up front. Many smaller organizations combine all of those particular services under one “mail.domain.com” domain, but larger organizations, especially those that have grown up among a number of Exchange versions, might have them split apart.
Exchange Server 2016 requires that you bring all of these individual domains into Exchange if those domains are located in the same Active Directory geographical site. That’s fine for a couple of domains, but if you have six or seven, it may be a different story. You will need to prepare DNS changes (new A records or, better yet, CNAME records so that you can switch up servers without hanging new aliases out) and new SSL certificates for the services, and if you are using load balancing, you will need to switch up that profile as well.
Perhaps this is a great time to consolidate namespaces for your organization to make the migration much less complex?

2. Outlook (on the desktop) version control

The version of Outlook installed on the desktops that your clients use may very well drive your migration timeline. Outlook 2003 and 2007 cannot connect to Exchange Server 2016, namely due to the Autodiscover service that changes how it responds to client requests in 2016 in a way that these older versions of Outlook do not currently understand. These desktop versions of Outlook will not be updated to work with Exchange 2016. Interestingly, you can still use Outlook 2007 with Office 365, even though Office 365’s Exchange version is based on the 2016 product, but that could change at any time.
For larger organizations, this will generally mean running a parallel Exchange 2007, 2010, or 2013 operation while introducing some Exchange Server 2016 machines into the mix as well as scheduling user migrations for those clients who are already on later versions of Outlook for the first wave of migrations. For smaller shops, this may mean you focus on upgrading Office first before you proceed down the migration path. To get those stragglers on your new Exchange environment, you will need to also schedule them for Outlook upgrades or relegate them to using their mobile devices and Outlook Web App (ahem, excuse me, “Outlook on the web”).

3. Certificate problems

One of the most common issues you will encounter during or just after a migration is a certificate error on your clients. This mainly relates to the fact that Exchange, during installation, registers a service connection point (SCP) in Active Directory for the Autodiscover service, but it registers using the server’s actual domain name and not an alias for the service that you may have chosen (and may have used to register and purchase the certificate you are using from a trusted third party certification authority). You will need to switch this SCP registration for the domain name you used in the certificate so that they match, and the warning will go away.
The fix is a quick PowerShell command away. First, see what the current SCP registration domain is:
Get-ClientAccessService -Identity YOUREXCHANGEMACHINE | Select AutodiscoverServiceInternalUri

Then, change it to the one that matches your certificate namespace. In the following example, I’ll assume you have consolidated your namespaces into the generic “mail”:

Set-ClientAccessService -Identity YOUREXCHANGEMACHINE -AutoDiscoverServiceInternalUri https://mail.yourdomain.com/Autodiscover/Autodiscover.xml

Restart internet information services (IIS) on the affected machine just for good measure.