简体   繁体   中英

how to get the last login date and created date from azure active directory through C#

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var signIns = await graphClient.**AuditLogs**.SignIns
    .Request()
    .GetAsync();

I will not able to read the AuditLogs from graphclient. Could you pleas help to get the lastlogin date and created date from the azure AD using C# code.

Getting this below error while reading the data:

Error CS1061 'GraphServiceClient' does not contain a definition for 'AuditLogs' and no accessible extension method 'AuditLogs' accepting a first argument of type 'GraphServiceClient' could be found (are you missing a using directive or an assembly reference?)

Based on MS DOC:

Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API .

The below code works for Microsoft Graph SDKs with the beta API:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var users = await graphClient.Users
    .Request()
    .Select("displayName,userPrincipalName,signInActivity")
    .GetAsync();

The below code is used to list the sign-in time of users with a specific display name.

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var users = await graphClient.Users
    .Request()
    .Filter("startswith(displayName,'Eric')")
    .Select("displayName,signInActivity")
    .GetAsync();

For more detailed information, please visit listing the users data through C# code .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM