FunctionsPublic/Get-GraphDeviceManagementScriptAssignment.ps1

<#
.SYNOPSIS
Get the configured Intune Management script assignments
 
.DESCRIPTION
Retrieves all the configured Management script assignments within Intune
 
.PARAMETER accessToken
A Microsoft Graph API access token with the required permissions
 
.PARAMETER deviceManagementScriptID
The management script assignment ID to get the assignments for
 
.PARAMETER nextLink
Next link if paging is required
#>

function Get-GraphDeviceManagementScriptAssignment
{
    [CmdletBinding()]
    param(
        [parameter(Mandatory=$true)][psobject]$accessToken, 
        [parameter(Mandatory=$true)][string]$deviceManagementScriptID, 
        [parameter(Mandatory=$false)][string]$nextLink
    )
    #
    # Get all existing groups
    #
    if($nextLink.Length -eq 0)
    {
        $responseBody = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/deviceManagement/deviceManagementScripts/$($deviceManagementScriptID)/assignments" -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    }
    else
    {    
        $responseBody = Invoke-RestMethod -Uri $nextLink -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    }
    
    if($null -eq $responseBody.id)
    {
        $responseResult = $responseBody.value
    }
    else
    {
        $responseResult = $responseBody
    }

    #
    # Retrieve additional results when there are additional results available
    #
    if($responseBody.'@odata.nextLink'.Length -gt 0)
    {
        $responseResult += Get-GraphDeviceConfigurationAssignment -accessToken $accessToken -nextLink $responseBody.'@odata.nextLink'
    }

    return $responseResult
}