Kasowanie, Listowanie, wyłączenie kont PC w AD

#ustawienie max wieku komputerów:
$then = (Get-Date).AddDays(-90)

#Wylistowanie tych komputerów, które nie logowały się ostatnio:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | FT Name,lastLogonDate

#Wyłączenie kont nieaktywnych komputerów:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Set-ADComputer -Enabled $false

#Usunięcie nieaktywnych komputerów:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Remove-ADComputer

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>