Use PowerShell to Manage Exchange Online in Office 365

ScriptingGuy1

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell implicit remoting to manage Exchange Online users.

Microsoft Scripting Guy, Ed Wilson, is here. This afternoon I am looking over my presentations for the PowerShell Summit in Bellevue, Washington. It will be April 28 – 30, 2014, and I am making three presentations. So I need to prepare. There will be a bunch of really cool Windows PowerShell people speaking and attending. This is the stuff that geeks dream about. The Scripting Wife will also be there. Don’t miss out.

     Note  This is the fourth in a series of Hey, Scripting Guy! Blog posts where I talk about using Windows PowerShell
     with Office 365.

Make the connection

The first thing I need to do to use implicit remoting is create a new Windows PowerShell session to the remote location. The configuration name that I use is Microsoft.Exchange. The connection URI for me is https://outlook.office365.com/powershell. I have read other blogs that state the connection URI is https://ps.outlook.com/powershell. I am not sure if this is because it was an older version of Exchange in Office 365, or if it is simply the URI that they need to use.

I experimented with a few things until I found it. I figured it would be easier and quicker than trying to find out why theirs was different. Anyway, I figured it out by looking at the URL in the Exchange admin center. This is shown here:

Image of menu

I have my credentials stored in an XML file. (I talked about this in Use PowerShell to Explore Office 365 Installation.) Therefore, I do not need to type my credentials.

After I figure out the ConnectionURI, I use the following command to create a new Windows PowerShell remote session and to store the returned session in the $ex variable (this is a single-line command that is wrapped):

$ex = New-PSSession -ConfigurationName Microsoft.Exchange

-ConnectionUri https://outlook.office365.com/powershell -Credential (Import-Clixml C:\fso\cred.xml)

-Authentication basic -AllowRedirection

Next I import the session into my current Windows PowerShell shell. To do this, I use the **Import-PSSession **cmdlet as shown here:

Import-PSSession $ex

I now use the Get-Module cmdlet to see what modules I have in my session:

Get-Module

At this point, I pause and take a deep breath and look over my Windows PowerShell shell. It is shown in the image that follows:

Image of command output

The next thing I like to do is to use Get-Command on the module. The module name is a temporary name, but by using tab expansion, it is really easy to get to. The following image shows some of the cmdlets:

Image of command output

I can now use Windows PowerShell cmdlets that are very similar to the standard Exchange cmdlets I have used in the past. For example, I can get a Mailbox User report by using the Get-Mailbox cmdlet. The command and output are shown here:

Image of command output

I can even access mailbox statistics for an individual mailbox or for all mailboxes. If I want the information for all mailboxes, I can simply pipe the results from Get-Mailbox to Get-MailboxStatistics. This command is shown here:

Get-Mailbox | Get-MailboxStatistics

The command and output from the command are shown in the following image:

Image of command output

I can find mailboxes where no one has signed in, as shown here:

Get-Mailbox | Get-MailboxStatistics | where {-not $_.lastlogontime}

If I need a report of the number of active mailboxes, and the number of created accounts, I can use the Get-MailboxActivityReport cmdlet. It generates a number of helpful reports. For example, to produce a daily report, I use the command in the image that follows:

Image of command output

That is all there is to using Windows PowerShell sessions and implicit remoting to connect to Exchange Online in Office 365. Office 365 Week will continue tomorrow when I will talk about more cool stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

0 comments

Discussion is closed.

Feedback usabilla icon