Hi Folks,
Good Day.
Can anyone help me to update below powershel script?
below script find in my domain all the AD users accounts that have not been logged into for more than 90 days and export the report to .csv file. in addition what I want:
1. OU=Others, Sales --> exclude this OUs
2. Disable all the user based on 90 days export report .csv file
$domain = "test.com"
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
$timer = (Get-Date -Format yyyy-mm-dd)
# 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 givenname,Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('dd-MM-yyyy_hh:mm:ss')}} | Export-Csv c:\temp\90DaysInactive-$(Get-Date -format dd-MM-yyyy).csv NoTypeInformation
Many thanks for advance Help: