Good afternoon.
I am a tenant administrator, I need to obtain the last sign in of the users, currently I see that I get the following error, it is worth mentioning that I always use this script and I did get the information but a few days ago I started to receive this error, can you help me to know why the error occurs and share with me an alternative to obtain this information.
Thank you
-----Script-----
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "AuditLog.Read.All","User.Read.All"
#Set the Graph Profile
Select-MgProfile -Name "beta"
#Properties to Retrieve
$Properties = @(
'Id','DisplayName','Mail','UserPrincipalName','UserType', 'AccountEnabled', 'SignInActivity'
)
#Get All users along with the properties
$AllUsers = Get-MgUser -All -Property $Properties #| Select-Object $Properties
$SigninLogs = @()
ForEach ($User in $AllUsers)
{
$SigninLogs += [PSCustomObject][ordered]@{
LoginName = $User.UserPrincipalName
Email = $User.Mail
DisplayName = $User.DisplayName
UserType = $User.UserType
AccountEnabled = $User.AccountEnabled
LastSignIn = $User.SignInActivity.LastSignInDateTime
}
}
$SigninLogs
#Export Data to CSV
$SigninLogs | Export-Csv -Path "c:\info\SigInUsers.csv" -NoTypeInformation
----Error -----
Get-MgUser : Se han producido uno o varios errores.
En línea: 20 Carácter: 1