Processes in Microsoft 365 for setting up Office apps, redeeming product keys, and activating licenses.
Hello,
Thanks to the reply: I agree with you that the Get-mailboxstatistics could be the best option but the thing is that we have some users that just have access to office 365 apps, that is why we want to base on AzureAD.
Here is the full function I am using:
Function GetLastSignInDate { param ( [string]$guestUserID ) $startTime = (get-date).AddDays(-90).ToString("yyyy-MM-dd") $filter = "startsWith(userId,'" + $guestUserID + "')" Try { $Result = Get-AzureADAuditSignInLogs -Filter $filter -Top 1 | Select-Object CreatedDateTime, UserPrincipalName if ($Result.CreatedDateTime -lt $startTime) { #$output = ($Result.UserPrincipalName.ToString() + "," + $Result.CreatedDateTime.ToString()) #Write-host $output -ForegroundColor Green return $Result } } Catch { $message = $_ if ($message -like "*Too Many Requests*") { Write-host "Sleeping for 10 seconds due to throttling limitations..." -ForegroundColor Yellow sleep 10 #Nested function call to retry the entry that was throttled GetLastSignInDate $guestUserID } elseif ($message -like "*This request is throttled*") { Write-host "Sleeping for 10 seconds due to throttling limitations..." -ForegroundColor Yellow sleep 10 #Nested function call to retry the entry that was throttled GetLastSignInDate $guestUserID } elseif ($message -like "*null-valued*") { $output = ($guestUserID + ", Not Found") Write-host $output -ForegroundColor Gray } elseif ($message -like "*Invalid filter clause*") { $output = ($guestUserID + ", Invalid character") Write-host $output -ForegroundColor Gray } elseif ($message -like "*Error reading JToken*") { $output = ($guestUserID + ", Script stopped due to authentication token timeout") Write-host $output -ForegroundColor White -BackgroundColor Red exit } else { $output = ($guestUserID + ",Error - " + $message.ToString().SubString(0,15)) Write-host $output -ForegroundColor Red } }}
I tried to optimize the script but I am getting timeouts almost I increase the start date time. Indeed, if I search for all users that connected withing 2 days, it is working fine.
Regards