Powershell Script for disabling computer accounts

I found this script online (can’t remember where exactly), but have modified it to exclude an OU and output to a log file:

<CODE>

# This PowerShell Command will query Active Directory and return the computer accounts which have not logged for the past
# 60 days. You can easily change the number of days from 60 to any 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
# be found at technet – http://bit.ly/YpGWXJ –MWT, 03/12/13

import-module activedirectory # Activates the required module in PS for this script to work.

$then = (Get-Date).AddDays(-30) # The 30 is the number of days from today since the last logon.

Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | where-object {$_.DistinguishedName -notlike “*OU TO EXCLUDE*”} | FT Name,lastLogonDate > C:\SCRIPTS\Stale_Records.log

# 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 like to Remove these computer accounts, uncomment the following line:
# Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Remove-ADComputer

</CODE>