Export data from AzureAD using PowerShell

August 9, 2018 in office365, windows ‐ 2 min read

In this article I want to show you how Data can be exported from Azure AD using PowerShell At first you have to connect your PowerShell with AzureAD.

To do this use the PowerShell commandlet connect-azuread. This should spawn a pop-up asking you for authentication. Use Azure Credentials that have the permissions needed to at least read all properties.

image

If the connection worked it should look something like this

image

Getting the data

Here is a good reference for PowerShell commandlets related to AzureAD.

We use get-azureaddevice to get a list of the devices in the Azure Domain.

image

As you can see the devices do have an ObjectID, a DeviceID and a DisplayName. These are by far not the only Infos that are available regarding devices.

To get an overview of what values get stored for each device just take one at random (-objectid) and pipe to format list (fl).

image

In this case I would like to export data on the attributes DisplayName, ObjectId, ObjectType and ApproximateLastLogonTimeStamp.

These can be listed for all devices using the following command. get-azureaddevice | select DisplayName, ObjectId, ObjectType, ApproximateLastLogonTimeStamp

image

Exporting the data

For better visibility you can export this info to a CSV file. To do this pipe STDOUT to export-csv and use a local path to store the file.

In my case the command looks like this: get-azureaddevice | select DisplayName, ObjectId, ObjectType, ApproximateLastLogonTimeStamp | export-csv C:\temp\foo.csv

image

Now we can open the file, for example with excel. Just start excel and select Data > From Text / CSV.

image

In the import Dialoge select comma separated import and load the file.

image

Using this import method you can sort columns alphabeticaly.

image

Cheers, Ori