一、Get-User单用户查询

$User=Get-ADUser -identity wendy -Properties * 

二、Get-User多用户循环查询

$export=@()
$Users=Get-ADUser -Filter * -SearchScope Subtree -SearchBase "OU=xx,OU=xx,dc=xx,dc=xx,dc=xx" -Properties *
foreach($user in $users)
  {
  #$User=Get-ADUser -identity wendy -Properties *
  $name=$user.name
  #这里可以添加多类属性
  $info=New-Object Psobject
  $info |Add-Member -MemberType NoteProperty -Name 姓名 -Value $name
  $export+=$info
  }
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd')
$export |Export-Csv D:\ps\userPermissioninfo_$CurrentDate.csv -Encoding UTF8 -NoTypeInformation

三、ou查询

functions代码如下,参考http://www.JSchofield22.wordpress.com的代码

function Get-OUWithObjects
{ <#
.SYNOPSIS
Function to get all OUs that contain Users, Groups, or Contacts. .DESCRIPTION
This function requires Quest ActiveRoles AD Management to be installed. The purpose of this
script is to go out and find any and all OrganizationalUnits which contain Users, Groups, or
Contacts. It performs a count on each type of object and prints them to a CSV File. This is
a useful tool for any Admin getting ready to perform an Active Directory migration in order
to better understand the existing environment. This script does not require and special
privelages in order to run as you're only reading from Active Directory. .PARAMETER Domains
This allows you to input as many domains as you'd like to scan against. (ex.
-Domains "domain1","domain2","domain3" ) .PARAMETER OutFile
This specifies the directory path and file name for the CSV output. (ex. -Outfile c:\temp.csv) .NOTES
Name: Get-OUWithObjects.ps1
Author: Josh Schofield
DateCreated: 12/28/2012 .LINK http://www.JSchofield22.wordpress.com .EXAMPLE
Get-OUWithObjects -Domains "Domain1","Domain2" -OutFile "C:\temp\test.csv" #> param( [Parameter(Mandatory=$true)]
$Domains, [Parameter(Mandatory=$true)]
[string]$OutFile ) if ((Get-PSSnapin -Registered| where {$_.name -eq "quest.activeroles.admanagement"}) -eq $null){Write-Error "Quest.ActiveRoles.ADManagement NOT Installed"} else { Get-PSSnapin -Registered| where {$_.name -eq "quest.activeroles.admanagement"} | Add-PSSnapin | Out-Null if ((test-path $OutFile) -eq "True"){del $OutFile} $output = @() foreach ($domain in $domains) { Connect-QADService $domain Get-QADObject -Type "organizationalunit" -IncludedProperties name,type,parentcontainer,dn -SizeLimit 0| %{ $ouname = $_.name
$parentcontainer = $_.parentcontainer $adobjects = get-qadobject -SearchRoot $_.dn -SearchScope OneLevel -IncludedProperties type,name -SizeLimit 0 | where {(($_.type -eq "contact") -or ($_.type -eq "user") -or ($_.type -eq "group"))}
$users = $adobjects | where {$_.type -eq "user"}
$groups = $adobjects | where {$_.type -eq "group"}
$contacts = $adobjects | where {$_.type -eq "contact"} $results = "" | Select Domain, Name, UserCount, GroupCount, ContactCount, ParentContainer
$results.Domain = $domain
$results.Name = $ouname
$results.ParentContainer = $parentcontainer if ($users -ne $null) { $results.UserCount = $users.count } #End of User Check if ($groups -ne $null) { $results.GroupCount = $groups.count } #End of User Check if ($contacts -ne $null) { $results.ContactCount = $contacts.count } #End of User Check $output += $results Clear-Variable $results -ErrorAction SilentlyContinue
Clear-Variable $ouname -ErrorAction SilentlyContinue
Clear-Variable $parentcontainer -ErrorAction SilentlyContinue $adobjects = $null
$users = $null
$groups = $null
$contacts = $null } #End of Get QADObject OU } $output | Export-Csv $OutFile -NoTypeInformation }}

最新文章

  1. sublime3 的安装
  2. 修改mysql默认字符编码出现的Job failed to start解决方法
  3. neatbean 8+版本 配置
  4. If WCF Service side and Client side config is different?!
  5. javascript form 第22节
  6. Codevs 1800 假面舞会 2008年NOI全国竞赛
  7. iOS实践02
  8. ffmpeg中ff_scale_image()内存泄露
  9. TestNG--入门介绍教程
  10. orcl数据库锁等级研究小记
  11. zookeeper选举流程
  12. 查询sqlserver数据库表的记录数
  13. Scarpy 起始url 自定义代理 自定义去重规则
  14. 05 Django REST Framework 分页
  15. 集合-HashMap
  16. Cocoa 框架 For iOS(一) 框架的介绍,Objectivie-C运行时能力的解析等 (转载)
  17. UVa 10905 - Children&#39;s Game 排序,题目没有说输入是int 难度: 0
  18. js 一些兼容检测
  19. C#使用FFMPEG推流,并且获取流保存在本地,随时取媒体进行播放!
  20. perl 读写文件

热门文章

  1. server2008服务器IIS7 +PHP5.3出现500错误的排错方法
  2. CentOS6.6+Puppet3.7.4分布式部署Nagios监控系统
  3. JSP应用开发 -------- 电纸书(未完待续)
  4. Unity对象与Draw Calls的关系
  5. std::thread “terminate called without an active exception”
  6. PHP中的正则表达式及模式匹配
  7. NYOJ 78 圈水池 (入门级凸包)
  8. Spring可扩展的XML Schema机制
  9. 1. DataBinding - offical tutorial
  10. poj2987 Firing 最大权闭合子图 边权有正有负