Connect to Office 365 Exchange PowerShell

KB ID 0001410

Problem

If there’s one thing thats grown on me it’s PowerShell, After the last few versions of Exchange you can’t really escape it. So now we have so many clients with their Exchange in Office 365. The ability to connect to that, and use all your usual Exchange commandlets is a bonus!

WARNING: This process may end up with you getting an “Access is denied” error, if you are using modern authenticiction, or MFA. If so use this article instead.

Solution

If you haven’t already done so, you need to ‘slacken‘ your signing policy, (a little) before proceeding;

[box]Set-ExecutionPolicy RemoteSigned[/box]

Now to access Exchange online you need to be able to authenticate to it, the best way to do that is to ‘cache’ your logon credentials. (Unless you have ADFS Federation then you can skip this step). To enter your O365 creds execute the following command;

[box]$UserCredential = Get-Credential[/box]

Then create the settings for your remote session;

[box]$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection[/box]

Then to open the session;

[box]Import-PSSession $Session[/box]

DON’T FORGET: When you are finished, to disconnect the session with the following command;

[box]Remove-PSSession $Session[/box]

Related Articles, References, Credits, or External Links

NA

Exchange – Export Distribution Groups AND Members to a file

KB ID 0000209 

Problem

Yes you can use the Powershell commands,

Get-DistributionGroupMember –identity “group name” | ft name, primarysmtpaddress

But you have to do that for every group and I’ve tried Piping the Get-DistributionGroup in there but it does not seem to want to work 🙁

Solution

1. Download this script and extract it to the root of the Exchange servers C: drive.

2. On the Exchange server > Click > Start > All Programs > Microsoft Exchange Server 2007 > Exchange Management Shell.

3. Issue the following command cd “c:” {enter}

4. Issue the following command ./all_members.ps1 {enter}

5. On the Exchange Server navigate to C:Exchange_Groups.csv (open with Microsoft Excel).

Possible problem;

Powershell Scrpt signing Policy

Change scipt execution policy with a set execution command.

Depending on your script signing policy, you might see.

File {path} cannot be loaded the file {path} is not digitally signed. The script will not execute on the system. Please see “get-help about_signing” for more details..

If you see this enter the following,

Get-ExecutionPolicy {enter}

It will say Restricted, Remote Signed or All Signed “Take Note”

Issue the following command

Set-ExecutionPolicy Unrestricted {enter}

Then run the all_member script, when finished change it back with

Set-ExecutionPolicy {what it was earlier}{enter}

 

Related Articles, References, Credits, or External Links

All Credit to Jon-Alfred Smith – Who put the script here