禁用符合一定条件的AD对象 (含Filter参数的写法)

Get-ADComputer -Filter "(sAMAccountType -eq 805306369)" -SearchBase "OU=Computers,OU=Hangzhou - China,OU=TCS - China,OU=TCS - China,DC=apac,DC=TCS,DC=com" | Get-ADComputer -Properties DistinguishedName, lastLogon, lastLogonTimestamp | select DistinguishedName, @{name="LastLogon"; express={[DateTime]::FromFileTime($_.LastLogon)}},@{name="LastLogontimestamp"; express={[DateTime]::FromFileTime($_.LastLogontimestamp)}} | where {

    $_.lastlogon -lt  "2014/12/31 00:00:00" -and $_.lastlogon -gt "2014/1/1 00:00:00" 

} | foreach {

    Disable-ADAccount -Identity $_.DistinguishedName -WhatIf

}

 

你可能感兴趣的:(filter)