Komputer mengubah kata sandi akun mereka setiap 30 hari secara default. Jika komputer tidak mengubah kata sandi dalam jangka waktu lama, itu berarti mereka tidak lagi terhubung ke jaringan.
Skrip PowerShell ini akan menghasilkan 2 file teks. Satu untuk komputer yang dinonaktifkan, satu untuk objek akun komputer yatim. Anda harus memiliki modul PowerShell Direktori Aktif yang diinstal.
Dalam contoh ini, saya mengecualikan OU "Laptop Terenkripsi", karena mereka laptop mobile yang terputus untuk periode waktu yang lama. Anda dapat menghapus bagian itu jika Anda tidak memiliki pengaturan serupa
Import-Module ActiveDirectory
$Date = [DateTime]::Today
#Sets the deadline for when computers should have last changed their password by.
$Deadline = $Date.AddDays(-365)
#Makes the date string for file naming
$FileName = [string]$Date.month + [string]$Date.day + [string]$Date.year
#Generates a list of computer accounts that are enabled and aren't in the Encrypted Computers OU, but haven't set their password since $Deadline
$OldList = Get-ADComputer -Filter {(PasswordLastSet -le $Deadline) -and (Enabled -eq $TRUE)} -Properties PasswordLastSet -ResultSetSize $NULL |
Where {$_.DistinguishedName -notlike "*Encrypted Laptops*"} |
Sort-Object -property Name | FT Name,PasswordLastSet,Enabled -auto
#Generates a list of computer accounts that are disabled and sorts by name.
$DisabledList = Get-ADComputer -Filter {(Enabled -eq $FALSE)} -Properties PasswordLastSet -ResultSetSize $null |
Sort-Object -property Name | FT Name,PasswordLastSet,Enabled -auto
#Creates the two files, assuming they are not $NULL. If they are $NULL, the file will not be created.
if ($OldList -ne $NULL) {
Out-File "C:\users\marra\desktop\Old$Filename.txt" -InputObject $OldList
}
if ($DisabledList -ne $NULL) {
Out-File "C:\users\marra\desktop\Disabled$Filename.txt" -InputObject $DisabledList
}