Tag Archives: powershell

O365 – Export Licensed Users

While reviewing user account licensing status in my Office 365 tenant, I noticed that there is no Export button when the list is filtered by Licensed Users.  I’m not sure why there would not be a button for exporting the list as filtered because there is an Export button when you filter by Unlicensed Users (see screenshots below).

Active users list filtered by License Users — no Export button!  (Click to enlarge.)Licensed Users FilterActive users list filtered by Unlicensed Users — Export button.  (Click to enlarge.)Unlicensed Users Filter

The fix is to export a list using PowerShell!

Export a List of Licensed Users

Open PowerShell and connect to Office 365/MSOL (see instructions here if you have not done this part before).

Type the following code into PowerShell, changing the output file name and location as needed.

$users = Get-MsolUser -All | Where-Object {$_.IsLicensed -eq "TRUE"}
$users | Export-Csv -Path C:\Scripts\O365\LicensedUsers.csv

That’s all there is to it.  Now you have a list of Office 365 Licensed Users in .csv format.

O365 – How to Connect

Sometimes it’s difficult to find the simplest things because they are buried in other data.  Here are two commands that do just one thing–get you connected to your Office 365 account in the cloud.

Connect to Office 365/MSOL

Prerequisites:

  1. Install the 64-bit version of the Microsoft Online Services Sign-in Assistant: Microsoft Online Services Sign-in Assistant for IT Professionals RTW.
  2. Install the 64-bit version of the Windows Azure Active Directory Module for Windows PowerShell: Windows Azure Active Directory Module for Windows PowerShell (64-bit version).

Open the PowerShell ISE with Run as Administrator on your computer.  Type in the code below.  Run the code and enter your O365 user name and password and you’re connected.

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
Connect to Office 365/Exchange

Open the PowerShell ISE with Run as Administrator on your computer.  Type in the code below.  Run the code and enter your O365 user name and password.  You will be connected to an Office 365 Exchange session.

$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic –AllowRedirection
Import-PSSession $Session
Disconnect from Office 365/Exchange

It’s a good practice to remember to disconnect from your O365 Exchange session when you’re done.  Type the code below into your PowerShell session and you will be disconnected.

Remove-PSSession $Session

Now you can add these snippets to any script you create to work in your tenant.  How easy was that?