PowerShell Office 365: SMTP Email Sent with PowerShell via Office 365

In this example, I have an extremely simple function called MyCode. The purpose of the function is only to demonstrate us taking any PowerShell output then passing it ot the body of an email and sending that email.

Here is a look at the output:

Once we have the output from MyCode it is all about how we pass that over to the email. That is achieved by using Send-MailMessage.

Read More

Powershell Office 365: Building a Hash Table and a Custom PSObject to Get-UserInfo

Here is a script that will quickly tell you some mailbox information and some mailbox statistics for an Exchange Online such as Office 365 mailbox. This will also work with Exchange Shell on Exchange 2013 on Premises.

The data is collated from 2 different cmdlets, Get-MsolUser and Get-MailboxStatistics. The data is then used to create an advanced function called Get-UserInfo.

This post serves as a demonstration in building a hash table and a custom PSObject, one of the most important aspects of PowerShell scripting. It also serves to demonstrate the principal of gathering output from various cmdlets and bringing them together as one.

It has been assumed that you have installed the PowerShell Module called MSOnline and authenticated to Office 365 via PowerShell in the usual way.

If you were to “Dot Source” the script using PowerShell.exe then you would run it with the following :

Get-UserInfo -UPN user@mail.com -Verbose -ErrorLog

This script example will only support one UserPrincipalName input although can be easily changed to accept multiple, CSV input and accross the pipeline if required. This is outwith the scope of this post.

Read More

Call Office 365 Service Communications API and Return an Hourly Summary of Service Health Notices – Part 4

In part 4, we will now look to create the flow that will populate the nested folder called Live Updates. More information on the folder structure in part 1.

We will base this post mostly around part 3 as they are very similar in what they do but with a few subtle changes and enhancements.

Please familiarise yourself with part 3 as this post will only discuss the changes required in order to achieve an hourly live update summary.

On the My Flows page, select the Flow you have created from part 3 and choose Save as, now rename the flow to Live Incidents – Hourly Update (or similar).

The first modification we will make will be at the beginning to the Recurrence trigger.

This will run hourly and it can help by reminding you of the issues that are live and may be affecting your tenant.

If you work in a 24 hour environment, then this should work well for you. but what if your company is Monday to Friday business hours, say 8am to 5pm. Do we really need a summary of live service incidents on a Saturday or Sunday or at midnight?

I would suggest not, so right after the Recurrence trigger but before we initialise variable TenantID, ClientID & SecretID we have the option to stop the flow from running if out with the time constraints. I have written a separate blog on this called So you just want Flow running in business hours – 8am to 5pm so you may want to integrate these steps for this one.

Read More

Call Office 365 Service Communications API and Return New Service Health Notices – Part 3

Here is how I have managed to return the latest Service Health alert (only) from Office 365 “Office 365 Service Communications API”.

Office 365 New Service Alert Email

As any O365 admin will know, Microsoft won’t offer an inbuilt alert that will notify you by email when a new Incident arises so here is how I have chosen to get round that and here is a sneak peek of the output:

Firstly, we will need to register an app in Azure AD. Please see Register an App in the Azure Active Directory for instructions on how to do that.

Read More

Call O365 Endpoints Web Service and Return the Latest FQDNs – Part 2

Now we will look into an automated process that allows us to call the Office 365 IP Address and URL Web service and to have the news Endpoints returned in FQDN Format.

The full unformated worldwide list can be found here in JSON format & here in CSV format.

As part of the article, it explains how you can access the changes, essentially the newest updates since the month before. You can see the data here.

The URI looks like this – https://endpoints.office.com/changes/Worldwide/2018102900?singleVersion&clientRequestId=b10c5ed1-bad1-445f-b386-b919946339a7

This can be changed as and when a new version is published by Microsoft, but of course the output via the browser is in JSON format. So let’s walk through how I have captured the new FQDNs and emailed them to a shared mailbox. I did this with some help from Paul Andrew as he had detailed a good deal of the process at this blog.

Let’s begin …

Firstly, we will need to use a SharePoint list in order to compare old and new versions. It will look like the next image:

Go to SharePoint and click the Lists menu item, then click New, and select List to create a new list.

Read More