Export AzureAD data via Powershell

June 3, 2018 in office365 ‐ 2 min read

This article describes how you can export data from AzureAD using the PowerShell.

At first you have to connect your PowerShell with an AzureAD. To do this we use the connect-azuread commandlet.

This generates a pop-up asking for login credentials. Use an account that has access to the information you want to export.

image

Afterwards you should see a line like this.

image

Getting data

The following Microsoft page provides a good overview of AzureAD related PowerShell commandlets. https://docs.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0

We use get-azureaddevice to get a list of device objects in this domain.

image

As you can see the devices have the related information ObjectID, DeviceID and a DisplayName. These are the values _get-azureaddevice_displays by default but there are way more. We get an overview of all available values if we take a random device (-objectid) and pipe the output to format list (fl).

image

In this example I am interested in the values of DisplayName, ObjectId, ObjectType und ApproximateLastLogonTimeStamp.

We can now explicitly list these in a desired order. get-azureaddevice | select DisplayName, ObjectId, ObjectType, ApproximateLastLogonTimeStamp

image

 

Exporting the data

For better visibility you can export this data to a CSV file. To do this we pipe STDOUT to the export-csv commandlet and provide a local storage path.

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

image

Now we can open this exported CSV with excel for example. Just go to File > From Text / CSV.

image

In the following dialogue we define that the values presented are comma seperated and confirm with load.

image

This way you can easily sort alphabeticly and provide the output to a customer.

image

Cheers, Ori