利用Powershell查询AD中电脑

Get-ADComputer -Filter *

利用Powershell查询AD中电脑详细信息

Get-ADComputer -Filter * -Property *

查询用户详细信息

Get-ADUser-Identity"User1"-Properties


将用户"User1"的部门修改为"开发部",并启用该用户:

Get-ADUser-Identity"User1" | Set-ADUser-Department"Develop"-Enabled$true 

查询禁用的用户

Search-ADAccount-AccountDisabled–UsersOnly 

禁用、启用用户:

Disable-ADAccount-Identity"User1"

Enable-ADAccount-Identity"User1" 

查询登录并锁定的用户          

Search-ADAccount–LockedOut

(一)  筛选AD中被停用的用户

Search-ADAccount –AccountDisabled

Search-ADAccount –AccountDisabled>c:\name.txt

筛选AD中被停用的计算机账号,然后统一移动到discomputer组织单位中


 

Search-ADAccount -AccountDisabled -ComputersOnly | Move-ADObject -TargetPath "OU=discomputer,OU=IT

,DC=contoso,DC=Com"


使用下面命令可以查询某个OU下面已经禁用的计算机账号


 

Search-ADAccount -AccountDisabled -Searchbase "OU=IT,DC=Contoso,DC=Com"

-ComputersOnly     


查询

其他AD Powershell计算机、账户、组管理常用命令参考

查询OU内有哪些组


 Get-ADGroup -Filter * -Properties * -SearchBase "ou=group,dc=contoso,dc=com"


筛选AD中被停用的用户

Search-ADAccount AccountDisabled

返回超过89天未更改密码的用户

dsquery user "OU=UserOU,DC=domain,DC=com" -server dc.domain.com -limit 0 -stalepwd 89

返回超过89天未更改密码的且必须更改密码的用户

dsquery user "OU=UserOU,DC=domain,DC=com" -server dc.domain.com -limit 0 -stalepwd 89 | dsget user -samid -mustchpwd | find "yes"

另外如果只是查看过期的账号

search-adaccount -accountexpired

查看即将5天后过期的账号

search-adaccount -accountexpiring -timespan 5.00:00:00 | ft

精细查询 组内成员

 

Get-ADGroupMember -Identity test01  | ft samaccountname


查询OU下用户并输出文件

 

Get-ADUser -Filter * -Properties * -SearchBase "ou=业务,ou=产品部,ou=总部,ou=部门架构,dc=Contoso-Corp,dc=com" | ft samaccountname >>c:\move.txt


查询用户位于哪个组

 

 

 

Get-ADPrincipalGroupMembership lishengxian | fl

删除组内某个成员

Remove-ADGroupMember -Identity helpdesk -Members lishengxian -confirm:$false}


使用户退出所隶属的相关组 并确认操作               

get-aduser test10 -Properties memberof | %{$_.memberof} | Remove-ADGroupMember -Members test10 -Confirm:$false

http://social.technet.microsoft.com/wiki/contents/articles/5819.ad-powershell-for-active-directory-administrators.aspx