Powershell Command To List Inactive Computers

Hello Friends, powershell command can be used to get computers which are not logged into network from last x number of days. Below is the powershell command to list inactive computers.
# The number 180 is the number of days which will count from today since the last logon.

$noofdays = (Get-Date).AddDays(-180)

Get-ADComputer -Property Name, lastLogonDate -Filter {lastLogonDate -lt $noofdays} | FT Name, lastLogonDate

# Now, if you want to disable these computer, then run below command:

Get-ADComputer -Property Name, lastLogonDate -Filter {lastLogonDate -lt $noofdays} | Set-ADComputer -Enabled $false

# And now if you want to remove these computers: Get-ADComputer -Property Name, lastLogonDate -Filter {lastLogonDate -lt $noofdays} | Remove-ADComputer


Other Posts:

One thought on “Powershell Command To List Inactive Computers

Leave a Reply