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 ...
随机推荐
- cmd隐藏指定文件
隐藏文件: 或者带路径执行: 显示文件:
- import { Subject } from 'rxjs/Subject';
shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...
- 【Shader】人物选中高亮状态
Shader "OutLine/RedOutLine" { Properties { _Switch("Value",Range(0,1)) = 0 _Main ...
- Atitit.swt 线程调用ui控件的方法
Atitit.swt 线程调用ui控件的方法 1 SwingUtilities.invokeLater1 2 display.asyncExec方法1 3 display.timerExec(500 ...
- 简述 Python 类中的 __init__、__new__、__call__ 方法
任何事物都有一个从创建,被使用,再到消亡的过程,在程序语言面向对象编程模型中,对象也有相似的命运:创建.初始化.使用.垃圾回收,不同的阶段由不同的方法(角色)负责执行. 定义一个类时,大家用得最多的就 ...
- myeclipce怎么破解
MyEclipse安装文件下载,下载地址 http://www.jb51.net/softs/150886.html 你也可以进入官方网站下载:http://www.myeclipsecn.com/d ...
- Errors occurred while updating the change sets for SVNStatusSubscriber org.apache.subversion.javahl.
原因:eclipse-svn插件版本过低,导致不能识别svn客户端中的代码,从而报错 解决方法: 1.点击“Help”下拉菜单中的“Eclipse Marketplace”, 2.在弹出的窗口中,点击 ...
- JSON学习【转自慕课网】
视频网址 从慕课网视频里的PPT截图过来的,因为是用PHP讲的,而且后面讲的一般,所以只截取了前两节课的基础内容,其实只看一下第一张PPT就可以了.
- linux应用time和timezone
linux中应用层(非内核层)time是怎样处理的?时区是怎样设置的?夏令时时是怎样实现的?NTP时间同步是怎么回事?本篇文章就在嵌入式linux应用中time和timezone相关问题总结. 1. ...
- ORA-01036: 非法的变量名/编号
今天写程序时,往Oracle中插入二进制数据,出现错误ORA-01036:非法的变量名/编号,代码如下: strSql = "INSERT INTO KA99 (KA991,KA992,KA ...