{"id":5070,"date":"2024-03-28T18:22:39","date_gmt":"2024-03-29T01:22:39","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=5070"},"modified":"2024-03-28T18:24:47","modified_gmt":"2024-03-29T01:24:47","slug":"how-to-export-the-last-sign-in-time-for-all-users-in-azure-ad-using-microsoft-graph","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=5070","title":{"rendered":"How to Export the Last Sign-In Time for All Users in Entra ID (Azure AD) Using Microsoft Graph"},"content":{"rendered":"\n<p>Microsoft Graph is a powerful tool that allows administrators to manage their Azure AD tenant and automate tasks. One common task is to retrieve the last sign-in date time for all users in Azure AD. This information can be used to track user activity and identify any inactive accounts that may need to be disabled or deleted. In this article, we will explain how to use Microsoft Graph to retrieve the last sign-in date time for all users in Azure AD.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-prerequisites\">Prerequisites:<a href=\"https:\/\/stackoverflow.com\/collectives\/azure\/articles\/75885876\/how-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-micro#heading-prerequisites\">\u200b<\/a><\/h3>\n\n\n\n<p>To follow along with this tutorial, you will need the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Azure AD tenant<\/li>\n\n\n\n<li>Global administrator privileges<\/li>\n\n\n\n<li>PowerShell with the Microsoft Graph PowerShell module installed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-steps-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-microsoft-graph\">Steps to Retrieve the Last Sign-In Date Time for All Users in Azure AD Using Microsoft Graph:<a href=\"https:\/\/stackoverflow.com\/collectives\/azure\/articles\/75885876\/how-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-micro#heading-steps-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-microsoft-graph\">\u200b<\/a><\/h3>\n\n\n\n<p><strong>Step 1: Connect to Microsoft Graph<\/strong><br>First, open PowerShell and connect to Microsoft Graph using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connect-MgGraph -Scopes Directory.Read.All,AuditLog.Read.All\n<\/code><\/pre>\n\n\n\n<p><strong>Step 2: Export User Data with lastSignInDateTime to CSV<\/strong><br>Export the user data based on your requirement either for all users\/member users\/guest users, including the UserPrincipalName and Id, to a CSV file using the following command:<\/p>\n\n\n\n<p>For all users-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-MgUser -All -Property 'UserPrincipalName','SignInActivity','Mail','DisplayName' | Select-Object @{N='UserPrincipalName';E={$_.UserPrincipalName}}, @{N='DisplayName';E={$_.DisplayName }}, @{N='LastSignInDate';E={$_.SignInActivity.LastSignInDateTime}} | Export-Csv -Path C:\\usernew1.csv -NoTypeInformation -NoClobber\n<\/code><\/pre>\n\n\n\n<p>For all member users use-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-MgUser -All -Filter \"UserType eq 'Member'\" -Property 'UserPrincipalName','SignInActivity','Mail','DisplayName' | Select-Object @{N='UserPrincipalName';E={$_.UserPrincipalName}}, @{N='DisplayName';E={$_.DisplayName }}, @{N='LastSignInDate';E={$_.SignInActivity.LastSignInDateTime}} | Export-Csv -Path C:\\usernew1.csv -NoTypeInformation -NoClobber\n<\/code><\/pre>\n\n\n\n<p>For all guest users use-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-MgUser -All -Filter \"UserType eq 'Guest'\" -Property 'UserPrincipalName','SignInActivity','Mail','DisplayName' | Select-Object @{N='UserPrincipalName';E={$_.UserPrincipalName}}, @{N='DisplayName';E={$_.DisplayName }}, @{N='LastSignInDate';E={$_.SignInActivity.LastSignInDateTime}} | Export-Csv -Path C:\\usernew1.csv -NoTypeInformation -NoClobber\n<\/code><\/pre>\n\n\n\n<p>Sample Output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i.stack.imgur.com\/MVQu7.png\"><img decoding=\"async\" src=\"https:\/\/i.stack.imgur.com\/MVQu7.png\" alt=\"enter image description here\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-conclusion\"><strong>Conclusion:<\/strong><a href=\"https:\/\/stackoverflow.com\/collectives\/azure\/articles\/75885876\/how-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-micro#heading-conclusion\">\u200b<\/a><\/h2>\n\n\n\n<p>In this article, we have explained how to use Microsoft Graph to retrieve the last sign-in date time for all users in Azure AD. By exporting the user data to a CSV file and looping through it to retrieve the last sign-in date time, administrators can easily track user activity and identify any inactive accounts that may need to be disabled or deleted.<\/p>\n\n\n\n<p>Ref: <a href=\"https:\/\/stackoverflow.com\/collectives\/azure\/articles\/75885876\/how-to-retrieve-the-last-sign-in-date-time-for-all-users-in-azure-ad-using-micro\">How to Retrieve the Last Sign-In Date Time for All Users in Azure AD Using Microsoft Graph &#8211; Stack Overflow<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft Graph is a powerful tool that allows administrators to manage their Azure AD tenant and automate tasks. One common task is to retrieve the last sign-in date time for all users in Azure AD. This information can be used to track user activity and identify any inactive accounts that may need to be disabled <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=5070\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1249,238,239,10,1224],"tags":[1776,1775],"class_list":["post-5070","post","type-post","status-publish","format-standard","hentry","category-azure-microsoft","category-cloud","category-azure","category-microsoft","category-powershell","tag-aad-user-export-last-sign-in-powershell","tag-how-to-export-last-sign-in-for-all-azure-users-microsoft-graph"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/5070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5070"}],"version-history":[{"count":2,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/5070\/revisions"}],"predecessor-version":[{"id":5072,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/5070\/revisions\/5072"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}