Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Retrieves data from the Intune Data Warehouse
Function Get-IntuneDataWarehouseData {
# Function to query the Intune Data Warehouse for data
# Requires an access token to be created first via the New-IntuneDataWarehouseAccessToken function
[CmdletBinding()]
Param(
[Parameter()] # this is the custom feed URL for your for your tenant for the InTune Data Warehouse
$WarehouseUrl = "https://fef.msun02.manage.microsoft.com/ReportingService/DataWarehouseFEService?api-version=beta",
[Parameter()]
$DataEntity = "devices", # this is the Data Entity you wish to query
[Parameter()]
$Filter, # OData Query parameter
[Parameter()]
$Top, # OData Query parameter
[Parameter()]
$OrderBy, # OData Query parameter
[Parameter()]
$Select, # OData Query parameter
[Parameter()]
$Skip, # OData Query parameter
[Parameter()][Switch]
$ListDataEntities # Use this switch to list the available data entities
)
# Create the custom URL
$UriBuilder = new-object System.UriBuilder($warehouseUrl)
If ($ListDataEntities)
{
$UriBuilder = new-object System.UriBuilder($WarehouseUrl)
}
Else
{
$URI = $WarehouseUrl.Insert($WarehouseUrl.IndexOf("?"), "/$DataEntity")
# Add query parameters
If ($filter -ne $null)
{
$URI = "$URI&`$filter=$Filter"
}
If ($select -ne $null)
{
$URI = "$URI&`$select=$select"
}
If ($top -ne $null)
{
$URI = "$URI&`$top=$top"
}
If ($orderby -ne $null)
{
$URI = "$URI&`$orderby=$orderby"
}
If ($skip -ne $null)
{
$URI = "$URI&`$skip=$skip"
}
$UriBuilder = new-object System.UriBuilder($URI)
}
# Create an HttpClient
$HttpClient = New-Object System.Net.Http.HttpClient
$HttpClient.Timeout = [timespan]"00:10:00" # Extend the timeout to 10 minutes in case of slow network / high data volume
$HttpClient.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $AccessToken)
# Load the data
$Result = (($httpClient.GetAsync($uriBuilder.Uri).Result).Content.ReadAsStringAsync().Result | ConvertFrom-Json).Value
If ($ListDataEntities)
{
$Result = $Result.URL | Sort
}
$HttpClient.Dispose()
return $Result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment