Active Directory에서 30일 지난 hostname 삭제 powershell 명령어 입니다.
30일 지난 장비 관리 를 위한 powershell 입니다
Import-Module ActiveDirectory
#숫자만 30일
$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' 카테고리의 다른 글
Delete hostname 30 days old in Active Directory powershell (0) | 2019.05.21 |
---|---|
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 |
댓글