31 lines
1.3 KiB
PowerShell
31 lines
1.3 KiB
PowerShell
|
import-module ActiveDirectory
|
||
|
|
||
|
if (!($cred)) {
|
||
|
$cred = Get-Credential -Message "Enter your domain admin login:"
|
||
|
}
|
||
|
|
||
|
$AgedOutDays = -365 #store this as a negative number. How many days back should the PC have changed its password
|
||
|
$CSVPATH = 'C:\Users\eeckert\Downloads\AD-ToDelete.csv'
|
||
|
$computers = get-adcomputer -filter {(Enabled -eq $False)} -properties passwordlastset | where passwordlastset -le (get-date).adddays($AgedOutDays)
|
||
|
|
||
|
foreach ($computer in $computers) {
|
||
|
$Output = 'Moving ' + $computer.name + ' to disabled OU.'
|
||
|
Write-Output $Output
|
||
|
$DescText = 'Disabled: ' + (get-date)
|
||
|
$computer | set-adcomputer -Enabled $false -Credential $cred -Description $DescText
|
||
|
$computer | move-adobject -TargetPath "OU=Computers,OU=Disabled Objects,DC=mpe,DC=ca" -Credential $cred
|
||
|
}
|
||
|
|
||
|
# $CSVList = import-csv $CSVPATH -ErrorAction SilentlyContinue #get list of hostnames
|
||
|
|
||
|
# foreach ($computer in $csvlist) {
|
||
|
# $Output = 'Moving ' + $computer.hostname + ' to disabled OU.'
|
||
|
# Write-Output $Output
|
||
|
# $computer = Get-ADComputer $computer.hostname
|
||
|
# $DescText = 'Disabled: ' + (get-date)
|
||
|
# $computer | set-adcomputer -Enabled $false -Credential $cred -Description $DescText
|
||
|
# $computer | move-adobject -TargetPath "OU=Computers,OU=Disabled Objects,DC=mpe,DC=ca" -Credential $cred
|
||
|
# }
|
||
|
|
||
|
|