-
-
Save c3rberus/20bc3c9eff76cb915b2a9c4b88ec2a6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find computers that have not logged in for over 90 days | |
# Skip ConfigMgr Excluded OU | |
$DaysInactive = 90 | |
$time = (Get-Date).Adddays(- ($DaysInactive)) | |
$ComputerList = Get-ADComputer -Filter { LastLogonTimeStamp -lt $time -and enabled -eq $true } -SearchBase "OU=Computers,DC=CORP,DC=MIRZADEDIC,DC=CA" -Properties Name, LastLogonTimeStamp, DistinguishedName | Where { $_.DistinguishedName -notmatch "OU=ConfigMgr Excluded,OU=Computers,DC=CORP,DC=MIRZADEDIC,DC=ca" } | |
# Disable computer | |
# Move to ConfigMgr Excluded OU | |
ForEach ($Computer in $ComputerList) | |
{ | |
Write-Output "Disabled: $($Computer.Name)" | |
Set-ADComputer $Computer.Name -Enabled $false -Verbose | |
Move-ADObject -Identity $Computer.DistinguishedName -TargetPath "OU=ConfigMgr Excluded,OU=Computers,DC=CORP,DC=MIRZADEDIC,DC=CA" -Verbose | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment