Powershell script assistance

Copper Contributor

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 spreadsheetscript.png

 

 

1 Reply

@shell-learner 

 

Hi there.

 

You're using the wrong module and command for two reasons:

 

  1. 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;
  2. 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:

 

 

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