Graph Powershell SignInActivity.LastSignInDateTime very slow
Hello,
I have a list of guest users Im trying to audit and one of tasks would be getting a last sign in date so we can remove the oldest as usual.
There is one script that proved to be working the best for me, but execution is very slow for the users that probably do not have a last sign in date due to they are a very old abandoned guest account or did not accept the invitation. It gets “stuck” on those for a while which slows down the process and going over significant amount of users proves unreasonably long. It gets over those eventually and continues, but I cant run the script for so long for every user that does not have last sign in date saved.
Is there a way to make this faster or maybe skip the ones that take the longest? I think there may be a way to improve this method, but Im not that proficient with Graph and Powershell, so seeking advice.
Here is the script:
Hello,I have a list of guest users Im trying to audit and one of tasks would be getting a last sign in date so we can remove the oldest as usual. There is one script that proved to be working the best for me, but execution is very slow for the users that probably do not have a last sign in date due to they are a very old abandoned guest account or did not accept the invitation. It gets “stuck” on those for a while which slows down the process and going over significant amount of users proves unreasonably long. It gets over those eventually and continues, but I cant run the script for so long for every user that does not have last sign in date saved. Is there a way to make this faster or maybe skip the ones that take the longest? I think there may be a way to improve this method, but Im not that proficient with Graph and Powershell, so seeking advice. Here is the script:# Connect to Microsoft GraphConnect-MgGraph -Scopes “Directory.Read.All”, “AuditLog.Read.All”$users = Import-Csv -Path “C:TempGuestUsers.csv”$signininfo = @()#Counter$i=1#Loop for all usersForeach ($u in $users) { $signininfo += Get-MgUser -UserId $u.Id -Property displayName,userPrincipalName,usertype,accountenabled,signInActivity,createdDateTime | select displayName,userPrincipalName,usertype,accountenabled,createdDateTime,@{Name = ‘LastSignInDateTime’; Expression = {$_.SignInActivity.LastSignInDateTime}} #Counter $i $i++}$signininfo |Export-Csv -Path C:TempSignininfo.csv -NoTypeInformation -Encoding UTF8 Read More