Powershell Get Domain User的几种方法
一、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 }}
Powershell Get Domain User的几种方法的更多相关文章
- Powershell Get Domain Mailbox的几种方法
一.Disconnected Mailboxes 1.Finding Disconnected Mailboxes The first function is called Get-Disconnec ...
- Powershell Get Domain Group的几种方法
Group常见属性介绍: 一.Get-ADGroup获取群组(如下例循环获取群组的发送权限) #群组的发送权限info $groups=Get-ADGroup -filter * -SearchSco ...
- ASP.NET Core设置URLs的几种方法
前言 在使用ASP.NET Core 3.1开发时,需要配置服务器监听的端口和协议,官方帮助文档进行简单说明,文档中提到了4种指定URL的方法 设置ASPNETCORE_URLS 环境变量: 使用do ...
- SQL Server启动的几种方法
SQL Server 启动有以下几种方法: (1)在Control Panel——Administrative Tools——Services,找到SQL Server (XXX)进行启动. 其中XX ...
- Ajax跨域的几种方法以及每种方法的原理
js中几种实用的跨域方法原理详解 这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协 ...
- 【总结】清除webbrowser cookie/session的6种方法
下面是我测试下来的6种清除webbrowser中cookie的6种方法: //方法一:调用 wininet.dll清除cookie (推荐) SuppressWininetBehavior(); // ...
- GRIDVIEW传值的两种方法
第一种方法:在onselectedindexchanged中写事件 第二种方法:OnRowCommand事件 前端页面: <%@ Page Language="C#" Aut ...
- iOS 本地存储四种方法
在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好.下面介绍⼀一下数据保存的方式: 1.NSKeye ...
- HibernateTemplate、HibernateDaoSupport两种方法实现增删改查Good(转)
Spring+Hibernate两种方法实现增删改查 首先,定义一个Customer的bean类,设置好Customer.hbm.xml文件.再定义好一个Dao接口.准备好一个jdbc.propert ...
随机推荐
- CentOS源码编译安装Nginx
安装编译用到的软件: yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel 现在到http://nginx.o ...
- LNMP架构四
php-fpm的pool(连接池) 我们查看php的进程时,会发现,在最后一个pool的选项,而这个就是我们在php-fpm配置文件里写的一个连接池. [root@bogon linux.com]# ...
- php 面象对象类自动加载
//自动加载第一步 function myload($class) { require('./'.$class.'.class.php'); } //注册一个函数为自动触发函数 spl_autoloa ...
- 解决WinForm界面闪烁问题
前言 之前將.net 1.1 Windows Form程式升級到.net 4.0,結果在開畫面時,閃的非常利害! 於是就開始找解決方法. 研究及解決 開始找到了設定DoubleBuffer=true ...
- 使用 P3P 规范让 IE 跨域接受第三方 cookie
前两天帮同事处理一个 js 跨域问题,使用 jsonp 跨域提交用户名密码请求,实现自动登录第三方网站,即 SSO(single-sign-on) 单点登录,一处登录处处登录.在 Chrome 下没问 ...
- ManipulationStarted,ManipulationCompleted,ManipulationDelta
一.获取某个元素相对另一元素的相对位置 1.使用TransformToVisual获取某个元素相对于另外一个元素的偏移量. 例如:要获得rect相对于LayoutRoot的偏移量,就将LayoutRo ...
- 140726暑期培训.txt
1. 输入多组数据的时候 while(scanf("%s",s)!=EOF) while(gets(s)!=NULL) 用gets和scanf不 ...
- MySQL分组查询获取每个学生前n条分数记录(分组查询前n条记录)
CREATE TABLE `t_test` ( `id` ) NOT NULL AUTO_INCREMENT, `stuid` ) NOT NULL, `score` ) DEFAULT NULL, ...
- HTML5坦克大战(1)绘制坦克
坦克尺寸如下: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...
- 碉堡完整的高性能PHP应用服务器appserver
完全企业级的开发模式,是一个多线程的 PHP 应用服务器,实现真正多线程的 PHP 编程,高效安全而且快速,以Magento 为例比基于 Nginx的标准安装要快 50%.概念上非常像 Java 的 ...