Powershell 管理AD命令三条

场景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
相关文章
相关标签/搜索