PowerShell queries for long-running computer objects that are not logged in the AD domain

Source: Internet
Author: User

Use the PowerShell command to query Active Directory for a long time without logging on to the computer account. This article takes 60 days as an example, you can modify as needed.


The following script is given:


# this PowerShell Command would query Active Directory and return the computer accounts which has not logged for the past

# days.  can easily change the number of days from the number of your choosing. Lastlogondate is a Human

# Readable conversion of the lastLogonTimestamp (as far as I am able to discern. More details about the timestamp can


$then = (get-date). AddDays ( -60) # The number of days from today since to the last logon.


Get-adcomputer-property name,lastlogondate-filter {lastlogondate-lt $then} | FT name,lastlogondate


# If you would like to Disable these computer accounts, uncomment the following line:

# get-adcomputer-property Name,lastlogondate-filter {lastlogondate-lt $then} | Set-adcomputer-enabled $false


# If you would as to Remove these computer accounts, uncomment the following line:

# get-adcomputer-property Name,lastlogondate-filter {lastlogondate-lt $then} | Remove-adcomputer


PowerShell queries for long-running computer objects that are not logged in the AD domain

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.