Functions/Get-DiscoveredDevices.ps1

<#
.SYNOPSIS
Retrieves a list of discovered devices for a specified cloud app within a specified time frame.
 
.DESCRIPTION
The Get-DiscoveredDevices function retrieves a list of discovered devices for a specified cloud app within a specified time frame. The function requires the stream ID, app ID, and time frame as parameters.
 
.PARAMETER streamID
The ID of the stream that contains the cloud app data.
 
.PARAMETER appID
The ID of the cloud app.
 
.PARAMETER timeframe
The time frame for which to retrieve the discovered devices. Valid values are "LastHour", "LastDay", "LastWeek", and "LastMonth".
 
.EXAMPLE
Get-DiscoveredDevices -streamID "1234" -appID "5678" -timeframe "LastDay"
 
This example retrieves a list of discovered devices for the cloud app with ID "5678" within the last day of data in the stream with ID "1234".
 
#>

function Get-DiscoveredDevices {
    param (
        [Parameter(Mandatory = $true)]
        [string]$streamID,
        [Parameter(Mandatory = $true)]
        [string]$appID,
        [Parameter(Mandatory = $true)]
        [stream_time_frame]$timeframe
    )

    Begin {
        $streamTimeFrameObject = [StreamTimeFrame]::new()
        $streamTimeFrame = $streamTimeFrameObject.$timeframe
        $ErrorActionPreference = 'Stop'
        $resourceGraph = "https://graph.microsoft.com"
        $discoveredDevicesEndpoint = "$resourceGraph/beta/security/dataDiscovery/cloudAppDiscovery/uploadedStreams/$streamID/$streamTimeFrame/$appID/microsoft.graph.security.endpointDiscoveredCloudAppDetail/devices"
    }
    Process {                  
                    $response = Invoke-GraphAPI -Uri $discoveredDevicesEndpoint -Method Get
                    return $response.value   
    }
}