Forum Discussion
shell-learner
Aug 09, 2023Copper Contributor
Powershell script assistance
I'm still very much new to powershell, but I've worked on a script that would populate a csv file with the last login date for the users that are in my csv file. It reads in my csv file fine, but it doesn't give me the last login date in the csv spreadsheet
1 Reply
Sort By
- LainRobertsonSilver Contributor
Hi there.
You're using the wrong module and command for two reasons:
- The AzureAD/AzureADPreview modules are deprecated and don't have a particularly long lifespan left. You want to move to the Microsoft.Graph.* modules instead;
- The Get-AzureADUser does not expose the lastSignInDateTime attribute, as noted in the official Microsoft literature below:
How to manage inactive user accounts - Microsoft Entra | Microsoft Learn
At a minimum, the two modules you will need to install are:
- Microsoft.Graph.Authentication;
- Microsoft.Graph.Uses.
Optionally, though I'd recommend it, you'll also want to install:
- Microsoft.Graph.Beta.Users
Once you have those installed, you'll want to make use of one or both of the following:
- Get-MgUser (Microsoft.Graph.Users) | Microsoft Learn
- Get-MgBetaUser (Microsoft.Graph.Beta.Users) | Microsoft Learn
The "beta" modules and commandlets are often referred to as they have a tendency to expose a lot more data than is available from the v1.0 endpoint, but it's entirely your call.
Cheers,
Lain