一些获取AD中用户信息的powershell名, 非常实用。

# Search for all users in the domain, using PowerShell v1 syntax
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.Filter = '(objectcategory=user)'
$Searcher.FindAll().Count

# Search for all users in the domain using [adsisearcher] type accelerator, PowerShell v2 syntax
([adsisearcher]'(objectcategory=user)').FindAll().Count

# Search for administrator and display its properties
([adsisearcher]'(samaccountname=administrator)').FindOne()
([adsisearcher]'(samaccountname=administrator)').FindOne().properties

# Display pwdlastset parameter of Administrator
$ADSIAdmin = ([adsisearcher]'(samaccountname=administrator)').FindOne()
$ADSIAdmin.properties.pwdlastset

# [adsisearcher] always returns arrays, to retrieve the correct data index into the array
$ADSIAdmin.properties.pwdlastset.GetType()
$ADSIAdmin.properties.pwdlastset[0].GetType()

# Use the DateTime .NET Class to convert the FileTime to a DateTime object
[DateTime]::FromFileTime($ADSIAdmin.properties.pwdlastset[0])

# Search for a computer account, samaccountname includes dollar sign
([adsisearcher]'(samaccountname=jbdc01)').FindOne()
([adsisearcher]'(samaccountname=jbdc01$)').FindOne()

# Search for all users that do not have homedirectory attribute set
([adsisearcher]'(!homedirectory=*)').FindAll()
([adsisearcher]'(&(objectcategory=user)(!homedirectory=*))').FindAll()
([adsisearcher]'(&(objectcategory=user)(!homedirectory=*))').FindAll().Count

 

 

其他的可以参考以下网址:

http://www.jaapbrasser.com/wp-content/uploads/2012/11/Adsisearcher-Examples.txt

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值