Powershell Script - Active Directory - Move expired computer objects to disabled computers OU

Hello Experts,
I've been tasked with creation of an OU that contains computers/workstations that hasn't been logged onto in more than 90 days, this OU will be linked to an SCCM collection so that we can delete the stale computer objects out of SCCM, to try and keep both AD and SCCM aligned,
Can you please point me to a Powershell Script that can do what I'm after in AD, move computer objects to a OU in AD, disable the computer object, and tattoo a date when the object was disabled,
Many thanks in advance,
Craig PaulsenSenior Systems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Try this:
Change the first 2 lines accordingly

$Domain = "yourDomainname"   #   eg. "contoso"
$TargetOu="OU=DisabledPCs,OU=Computers,DC=contoso,DC=com"


$DaysAgo = (Get-Date).AddDays(-90)
$StaleComputers = Get-ADComputer -Filter {(LastLogonTimeSTamp -lt $DaysAgo)} -Properties LastLogonTimeStamp -Server $Domain

           
foreach ($StaleComputer in $StaleComputers) 
{
    Set-ADComputer -Identity $StaleComputer -Enabled $false -Server $Domain
    Move-ADObject -Identity $StaleComputer -TargetPath $TargetOu -Server $Domain
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Craig PaulsenSenior Systems EngineerAuthor Commented:
thanks, your script appears to the job as well,
Craig PaulsenSenior Systems EngineerAuthor Commented:
thanks,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SCCM

From novice to tech pro — start learning today.