Hi Glenn Maxwell,
Thank you for posting in the Q&A Forums.
$users = Import-Csv -Path “C:\path\to\your\users.csv” # Assuming the CSV file contains the “UPN” columns
foreach ($user in $users) {
$upn = $user.UPN
$uri = “https://graph.microsoft.com/v1.0/users/$upn/signInActivity”
$token = GetAccessToken() # Here you need to implement a function to get the OAuth access token
$headers = @{
Authorization = “Bearer $token”
}
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers
if ($response.value.Count -gt 0) {
$lastSignInDateTime = $response.value[0].lastSignInDateTime
Write-Host “User $upn last signed in at $lastSignInDateTime”
# Here you can add logic to check if the last login was more than 30 days ago
# and revoke or reassign the license as needed
} else {
Write-Host “No sign-in activity found for user $upn”
}
}
function GetAccessToken() {
# Here you need to implement the logic to get the OAuth access token.
# Typically involves a client ID, client key, resource URI (for Microsoft Graph it's https://graph.microsoft.com/)
# Use the ADAL or MSAL library to get the token
return “your_access_token_here”
}
Best regards
NeuviJ
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.