I've had a go but running into an error loading the adm-O365ObjectId attribute for the script you've linked
[Exception calling "Get" with "1" argument(s): "The 'adm-O365ObjectId' property cannot be found in the cache."] Unspecified error.
Here's the script i'm using:
# Search filter
$filterUsers = "(&(sAMAccountType=805306368)(|(!(msExchRecipientTypeDetails=*))(!(msExchRecipientTypeDetails:1.2.840.113556.1.4.804:=7241860145202))))"
$Context.DirectorySearcher.AppendFilter($filterUsers)
$AADlastlogoncolumnID = "{cb10b107-2f09-4016-8ffd-a6b0e1a9d6ca}"
# Add AAD ObjectID to the list of properties to fetch
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("adm-O365ObjectId")
# Generate report
try
{
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
#Bind to current search result
$searchResult = $searchIterator.Current
$user = $Context.BindToObjectBySearchResult($searchResult)
# Get access token for Microsoft Graph API
$token = $Context.CloudServices.GetAzureAuthAccessToken($user)
# Get the last logon date
$o365ObjectId = [Guid]$user.Get("adm-O365ObjectId")
$url = 'https://graph.microsoft.com/beta/users/' + $o365ObjectId.ToString() + `
'?$select=signInActivity'
$response = Invoke-RestMethod -Method GET `
-uri $url `
-Headers @{Authorization="Bearer $token"}
$AADlastlogonvalue = $response.value[0].signInActivity.lastSignInDateTime
# Add the user to the report
$columnValues = @{ }
$columnValues.Add($AADlastlogoncolumnID, $AADlastlogonvalue)
$Context.Items.Add($searchResult, $columnValues, $NULL)
}
}
finally
{
if ($searchIterator) { $searchIterator.Dispose() }
}