Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

Get Inactive User in Domain based on Last Logon Time Stamp

$
0
0

Dear All,

I have used below code to get inactive users from AD who has not logon since last 90 days, BUt am getting  wrong result set. It is displaying all the users.

# Gets time stamps for all User in the domain that have NOT logged in since after specified date # Mod by Tilo 2014-04-01 
import-module activedirectory  $domain = "domain.mydom.com"  $DaysInactive = 90  $time = (Get-Date).Adddays(-($DaysInactive))   # Get all AD User with lastLogonTimestamp less than our time and set to enable 
Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true-Properties LastLogonTimeStamp |   # Output Name and lastLogonTimestamp into CSV  select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('yyyy-MM-dd_hh:mm:ss')}} | export-csv OLD_User.csv -notypeinformation



Hari






Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>