본문 바로가기
powershell

Active Directory에서 30일 지난 hostname 삭제 powershell

by kogoza 2019. 4. 24.
반응형

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"

}

 

 

반응형

댓글