場景1:編輯器
清理長時間未登陸的計算機帳戶,適用於離職員工的計算機更名後,原有計算機帳戶依舊殘留在AD內。ide
365即爲365天未登陸。操作系統
Get-ADComputer -Filter * -Properties * | ?{((get-date) - $_.LastlogonDate).days -gt 365} | Move-ADObject -TargetPath "ou=離職人員計算機帳戶,dc=huabaotrust,dc=com" –verbose
場景2:get
篩選出某Computer_ALL此OU內全部的Windows XP的計算機it
利用operatingSystemVersion來匹配,5.1 (2600)即爲WinXP的版本號io
Get-ADComputer -Filter 'OperatingSystemVersion -eq" 5.1 (2600)"' -Properties * -searchbase "ou=COMPUTER_ALL,dc=xxx,dc=com" | move-adobject -TargetPath "ou=client2-xp,ou=COMPUTER_ALL,dc=xxx,dc=com" –verbose
場景3:ast
篩選出全部的180天內未登陸的,且操做系統爲Windows XP,且帳戶狀態爲啓用(而非已禁用)的計算機帳戶class
userAccountControl即爲帳戶的disable/enable屬性,在ADSI裏對應的是一串十六位數值,但利用ADSI編輯器可雙擊查看其十進制數值登錄
4096爲計算機帳戶處於enable狀態,disable狀態是4098 即 4096+2 ,這個2是怎麼來的,且看這裏 http://support.microsoft.com/kb/305144/zh-cncli
Get-ADComputer -Filter 'OperatingSystemVersion -eq" 5.1 (2600)"' -Properties * | where-object {$_.useraccountcontrol -eq "4096"} | ?{((get-date) - $_.LastlogonDate).days -gt 180} | select name,operatingsystem,LastLogondate