|
场景1:
清理长时间未登录的计算机账户,适用于离职员工的计算机改名后,原有计算机账户依旧残留在AD内。
365即为365天未登录。
Get-ADComputer -Filter * -Properties * | ?{((get-date) - $_.LastlogonDate).days -gt 365} | Move-ADObject -TargetPath "ou=离职人员计算机账户,dc=huabaotrust,dc=com" –verbose 场景2:
筛选出某Computer_ALL此OU内所有的Windows XP的计算机
利用operatingSystemVersion来匹配,5.1 (2600)即为WinXP的版本号
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:
筛选出所有的180天内未登录的,且操作系统为Windows XP,且账户状态为启用(而非已禁用)的计算机账户
userAccountControl即为账户的disable/enable属性,在ADSI里对应的是一串十六位数值,但利用ADSI编辑器可双击查看其十进制数值
4096为计算机账户处于enable状态,disable状态是4098 即 4096+2 ,这个2是怎么来的,且看这里 http://support.microsoft.com/kb/305144/zh-cn
Get-ADComputer -Filter 'OperatingSystemVersion -eq" 5.1 (2600)"' -Properties * | where-object {$_.useraccountcontrol -eq "4096"} | ?{((get-date) - $_.LastlogonDate).days -gt 180} | select name,operatingsystem,LastLogondate
|
|
|