Delete hostname 30 days in Active Directory powershell command.
It is powershell for 30 days past equipment management
Import-Module ActiveDirectory
# Only 30 days
$ DaysInative = 30
$ InactiveDate = (Get-Date) .Adddays (- ($ DaysInactive))
$ Computers = Get-ADComputer -Filter {LastLogonDate -lt $ InactiveDate -and Enabled -eq $ true} -Properties LastLogonDate | Select-Object Name, LastLogonDate, DistinguishedName
$ Computers = Get-ADComputer -Filter {LastLogonDate -notlike "*" -and Enabled -eq $ true} -Properties LastLogonDate | Select-Object Name, LastLogonDate, DistinguishedName
$ Computers = Search-ADAccount -AccountInactive -DateTime $ InactiveDate -ComputersOnly | Select-Object Name, LastLogonDate, Enabled, DistinguishedName
$ Computers | Export-Csv C: \ InactiveComputers.csv -NoTypeInformation
ForEach ($ Item in $ Computers) {
Remove-ADComputer -Identity $ Item.DistinguishedName -Confirm: $ false
Write-Output "$ ($ Item.Name) - Deleted"
}
'powershell' 카테고리의 다른 글
Problem when converting displayname to another character in office365 (0) | 2019.05.21 |
---|---|
Editing and exploiting powershell AD users (0) | 2019.05.21 |
powershell AD 사용자 편집 및 활용 (0) | 2019.04.24 |
office365 에서 displayname을 한글로 변환했을때 문제 (0) | 2019.04.24 |
Active Directory에서 30일 지난 hostname 삭제 powershell (0) | 2019.04.24 |
댓글